How does PHP handle integer indexed non-consecutive keyed arrays?
I'm curious a开发者_如何学编程s to how efficient it is in PHP to store an array with integer indices that are non-consecutive.
If I had an array
$b = array();
$b[1] = "Hello";
$b[18] = "World";
$b[999] = "Test";
Are those keys stored, and then hashed to a new array, how does PHP handle this?
From php wep site on array:
An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.
Executing print_r($b); on your code gives the following output:
Array
(
[1] => Hello
[18] => World
[999] => Test
)
精彩评论