Home >Backend Development >PHP Problem >How php arrays are stored in memory

How php arrays are stored in memory

(*-*)浩
(*-*)浩Original
2019-09-17 15:03:335521browse

How php arrays are stored in memory

Array definition (Recommended learning: PHP programming from entry to proficiency)

How php arrays are stored in memory$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.

How php arrays are stored in memory

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn