How do PHP arrays actually work? -
this question has answer here:
- are php associative arrays ordered? 3 answers
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.
Comments
Post a Comment