How do PHP arrays actually work? -


this question has answer here:

i'm learning php , i've got question that's bothering me. php arrays seem hashmaps internally. if give array key , value, has put key through sort of hashing function before placing in actual array, right? why then, if give array series of keys , values , dump these screen, php maintain order in entered values?

for instance:

$arr = array(); $arr[1] = 'one'; $arr[3] = 'three'; $arr[2] = 'two';  foreach($arr $key => $val)     echo "$key => $val<br>" 

would render "1 => one, 2 => two, 3 => three" in typical hashmap, instead "1 => one, 3 => three, 2 => two." me means there have both , order , key being maintained in whatever datatype is.

thanks in advance explanation.

you correct array being stored hash table or ordered map. basically, in php hash table.

see here: understanding php's internal array implementation


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -