Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

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 :)

Upvotes: 3

Views: 2014

Answers (2)

jon_darkstar
jon_darkstar

Reputation: 16768

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?

Upvotes: 0

Nikola Sivkov
Nikola Sivkov

Reputation: 2852

test it with var_dump($arr)

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

cheers :)

Upvotes: 3

Related Questions