According to my personal understanding, the array should be a contiguous space in the memory. Before using the array, you need to open up a blank memory of the specified size in the memory. If the declared size is smaller than the available continuous memory size, the error of memory overflow should be reported.
For children's shoes who have used PHP arrays, they should be able to quickly determine that the arrays in PHP do not have the above features. 1. the array declaration does not need to be determined by the size. 2. There is no upper limit for the array. Through these two points, we can determine that the arrays in PHP are a loose structure of the linked list, rather than continuous memory space.
Arrays in PHP can be divided into index arrays and associated arrays. An index array is a counting array structure. The associated array is an implementation of the map data structure, that is, the key-value structure.
The following examples are used to discuss the index array and associated array.
$ Arr = array (, 3, 'name' => 'misko _ lee ', 'age' => 22); // define an index and associate a Hybrid array
For ($ I = 0; $ I <count ($ arr); $ I ++)
Echo $ arr [$ I]; // here we can see the error message of subscript overflow.
The Cout ($ arr) function call returns the length of the $ arr array. However, the for loop can only output index arrays normally. Therefore, we can determine that the index array and the associated array are two different implementations. Therefore, it is proved that the arrays in PHP are loosely structured.
We also have the following conjecture about the index array:
$ Arr [100] = 100;
$ Arr [] = 101; // at this time, $ arr [] automatically increases the subscript by 101.
The above experiment proves our conjecture that the array counter in PHP does not count from the first address of the Array Memory, but is a pseudo counting method. Therefore, it is incorrect to use the counter to determine the array size.
The above comments are not reliable because they are gibberish. Students are welcome to make mistakes. Good people are safe for life.
Last PS sentence: If the array uses foreach for traversal, use the reset () function to reset the array pointer for traversal.