A little conjecture about the array model in PHP (by Misko Lee) _php tutorial

Source: Internet
Author: User
Tags map data structure
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.