简体   繁体   中英

PHP arrays and memory allocation

Random question that crossed my mind:
If I define an array in PHP like so:

$arr = Array();
$arr[7392171] = "some value";

How is this stored internally? Does it map the key 7392171 to "some value", or does it work like JavaScript and put 7392170 empty values before it?
I'm guessing it's the former, because indexed and associative arrays are the same (at least from my understanding) and comparable to objects in JavaScript.
So yeah, just wondering :)

test it with var_dump($arr)

if it created 739217 empty values you will see it :)

cheers :)

All arrays are stored associatively in PHP. Key names need not have any connection to its order.

Side question - This is done by hash map i guess?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM