note 74027 deleted from function.array-splice by felipe

From: Date: Sat, 05 Jan 2008 02:09:30 +0000
Subject: note 74027 deleted from function.array-splice by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134822@lists.php.net to get a copy of this message
Note Submitter: php barryhunter co uk ---- Following on from weikard's function here is a slight variation that accepts a key in the associative array to insert the new array after, instead of simply an index. <?php function array_insert(&$array, $position, $insert_array) { if (!is_int($position)) { $i = 0; foreach ($array as $key => $value) { if ($key == $position) { $position = $i; break; } $i++; } } $first_array = array_splice ($array, 0, $position); $array = array_merge ($first_array, $insert_array, $array); } ?>

« previous php.notes (#134822) next »