Insert a Key=>Value at the beginning of an array


/ Published in: PHP
Save to your folder(s)

There seems to be no easy way to insert a key and value at the beginning of an array, as array_unset does not allow you to specify a key. This is not a very efficient way to do it, but it works.

Pretend the array is currently: array("a"=>"b", "c"=>"d") and you would like "x"=>"z" at the beginning....

The snippet will result in $array being: array("x"=>"z", "a"=>"b", "c"=>"d")

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.