note 110646 deleted from function.array-unshift by danbrown

From: Date: Thu, 06 Dec 2012 14:16:10 +0000
Subject: note 110646 deleted from function.array-unshift by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192314@lists.php.net to get a copy of this message
Note Submitter: josh dot worden at cygnus dot com ---- 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; }

« previous php.notes (#192314) next »