Home>Article>Backend Development> How php arrays are stored in memory
Array definition(Recommended learning:PHP programming from entry to proficiency)
$arr[]='a';
1. Determine the type of the variable. If the system encounters a variable with square brackets, the system will think it is an array and will open up a memory space in the heap area
2. Create another memory space for a in arr, and store a in the area.
3. Open up a memory area in the stack to store the arr variable.
4. Assign the address of a in the heap area to arr.
$arr=’b’;
1. First find the memory space pointed to by the arr variable.
2. Calculate the currently occupied memory address in the arr space
3. Open up a memory space at a new address next to the occupied memory address to hold b.
Array access
echo $arr[1];
1. Find the value pointed to by the arr variable Memory address
2. Calculate the memory address of the location of the real array element through the subscript of the array
3. Get the value of the corresponding address
The above is the detailed content of How php arrays are stored in memory. For more information, please follow other related articles on the PHP Chinese website!