According to my own understanding, the array should be a contiguous space in memory. It is necessary to open a blank memory in memory before the array is used, and if the declared size is less than the available contiguous memory size, a memory overflow error should be reported.
For children who have used a PHP array, it should be able to quickly determine that the array in PHP does not have the above characteristics. One, the array declaration does not need to determine the size, and the array does not use the upper limit. With these two points, we can tell that the array in PHP is a loosely structured form of a list, not a contiguous memory space.
Arrays in PHP can be divided into indexed arrays and associative arrays of two forms. An indexed array is a count-type array structure. The associative array is an implementation of the map data structure, which is the structure of the key-value.
We have some discussions on indexed arrays and associative arrays using the following example.
$arr =array (the ' name ' = ' Misko_lee ', ' age ' =>22); Defines an index, an associative mixed-type array
for ($i =0; $i <>
echo $arr [$i]; Here we can see the error message of the subscript overflow
The Cout ($arr) function call returns the length of the $arr array. However, only the for loop can output an indexed array normally. Thus, we can judge that the indexed array and the associative array are two different implementations. It also proves that the array in PHP is a loosely-structured conjecture.
About indexed arrays We also have the following assumptions:
$arr [100]=100;
$arr []=101; At this point the $arr[] auto-grow subscript is 101.
The above experiment proves our conjecture that the array counters in PHP are not counted from the first address of the array memory, but rather a pseudo-counting method. Therefore, the use of counters to determine the size of the array is a complete error.
The above remarks are personal nonsense, with very unreliable factors. Welcome all Seniors Shoes pointed out the mistake. A good man is safe in life.
The last PS sentence: If the array uses a foreach traversal if it is not the reason for demand, use the Reset () function to traverse the array pointer to reset
http://www.bkjia.com/PHPjc/477973.html www.bkjia.com true http://www.bkjia.com/PHPjc/477973.html techarticle according to my own understanding, the array should be a contiguous space in memory. Before the array is used, it is necessary to open up a specified amount of blank memory in memory if the declared size is less than ...