note 27414 added to ref.array

From: Date: Thu, 05 Dec 2002 00:30:33 +0000
Subject: note 27414 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-40364@lists.php.net to get a copy of this message
I noticed a lack of a function to insert a value into a specified place in an array. Here'a a function I came up with that will do this: function array_insert(&$array, $value, $pos) { if (!is_array($array)) return FALSE; $last = array_splice($array, $pos); array_push($array, $value); $array = array_merge($array, $last); } It can be used like this: $a = array("zero", "one", "two", "three", "four", "five", "six", "seven", "eight"); array_insert($a, "POOP", 4); The array will now contain: ("zero", "one", "two", "three", "POOP", "four", "five", "six", "seven", "eight") -- http://www.php.net/manual/en/ref.array.php http://master.php.net/manage/user-notes.php?action=edit+27414 http://master.php.net/manage/user-notes.php?action=delete+27414 http://master.php.net/manage/user-notes.php?action=reject+27414

« previous php.notes (#40364) next »