note 14358 modified in function.array-unshift by vrana

From: Date: Tue, 17 Aug 2004 14:52:07 +0000
Subject: note 14358 modified in function.array-unshift by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79786@lists.php.net to get a copy of this message
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; $arr = array_reverse($arr, true); return count($arr); } ?> --was-- 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: function array_unshift_assoc(&$arr, $key, $val) { $arr = array_reverse($arr, true); $arr[$key] = $val; $arr = array_reverse($arr, true); return count($arr); } http://php.net/manual/en/function.array-unshift.php

« previous php.notes (#79786) next »