note 106570 added to function.array-unshift

From: Date: Sat, 19 Nov 2011 17:44:57 +0000
Subject: note 106570 added to function.array-unshift
Groups: php.notes 
Request: Send a blank email to php-notes+get-184573@lists.php.net to get a copy of this message
Sahn's example almost works but has a small error. Try it like this if you need to prepend something to the array without the keys being reindexed and/or need to prepend a key value pair, you can use this short function: <?php function array_unshift_assoc(&$arr, $key, $val) { $arr = array_reverse($arr, true); $arr[$key] = $val; return = array_reverse($arr, true); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 94.34.37.237 ---- Manual Page -- http://www.php.net/manual/en/function.array-unshift.php Edit -- https://master.php.net/note/edit/106570 Del: integrated -- https://master.php.net/note/delete/106570/integrated Del: useless -- https://master.php.net/note/delete/106570/useless Del: bad code -- https://master.php.net/note/delete/106570/bad+code Del: spam -- https://master.php.net/note/delete/106570/spam Del: non-english -- https://master.php.net/note/delete/106570/non-english Del: in docs -- https://master.php.net/note/delete/106570/in+docs Del: other reasons-- https://master.php.net/note/delete/106570 Reject -- https://master.php.net/note/reject/106570 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184573) next »