note 109396 deleted from function.array-unshift by danbrown

From: Date: Mon, 16 Jul 2012 15:20:04 +0000
Subject: note 109396 deleted from function.array-unshift by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189182@lists.php.net to get a copy of this message
Note Submitter: thegrandoverseer ---- I wrote this simple function to relocate an existing array element (name value pair) to the beginning of an array, by reference: function array_unshift_nvp(&$array, $keyname){ $newarray = array($keyname=>$array[$keyname]); //copy the node before unsetting unset($array[$keyname]); //remove the node $array = $newarray + array_filter($array); //combine copy with filtered array }

« previous php.notes (#189182) next »