note 110646 added to function.array-unshift
| From: | josh dot worden at cygnus dot com | Date: | Fri, 16 Nov 2012 16:37:47 +0000 |
| Subject: | note 110646 added to function.array-unshift | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192012@lists.php.net to get a copy of this message | ||
A small improvement on the previous anonymous example for prepending a key/value pair. Returning an
array_reverse tends to randomly flip the array when used iteratively. Also removed '='
from return statement to resolve syntax error.
<?php
function array_unshift_assoc(&$arr, $key, $val)
{
$arr = array_reverse($arr, true);
$arr[$key] = $val;
$arr = array_reverse($arr, true);
return $arr;
}
----
Server IP: 69.147.83.199
Probable Submitter: 208.86.102.194
----
Manual Page -- http://www.php.net/manual/en/function.array-unshift.php
Edit -- https://master.php.net/note/edit/110646
Del: integrated -- https://master.php.net/note/delete/110646/integrated
Del: useless -- https://master.php.net/note/delete/110646/useless
Del: bad code -- https://master.php.net/note/delete/110646/bad+code
Del: spam -- https://master.php.net/note/delete/110646/spam
Del: non-english -- https://master.php.net/note/delete/110646/non-english
Del: in docs -- https://master.php.net/note/delete/110646/in+docs
Del: other reasons-- https://master.php.net/note/delete/110646
Reject -- https://master.php.net/note/reject/110646
Search -- https://master.php.net/manage/user-notes.php