note 109396 added to function.array-unshift

From: Date: Fri, 13 Jul 2012 17:11:44 +0000
Subject: note 109396 added to function.array-unshift
Groups: php.notes 
Request: Send a blank email to php-notes+get-189125@lists.php.net to get a copy of this message
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 } ---- Server IP: 69.147.83.197 Probable Submitter: 98.177.154.189 ---- Manual Page -- http://www.php.net/manual/en/function.array-unshift.php Edit -- https://master.php.net/note/edit/109396 Del: integrated -- https://master.php.net/note/delete/109396/integrated Del: useless -- https://master.php.net/note/delete/109396/useless Del: bad code -- https://master.php.net/note/delete/109396/bad+code Del: spam -- https://master.php.net/note/delete/109396/spam Del: non-english -- https://master.php.net/note/delete/109396/non-english Del: in docs -- https://master.php.net/note/delete/109396/in+docs Del: other reasons-- https://master.php.net/note/delete/109396 Reject -- https://master.php.net/note/reject/109396 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189125) next »