note 23429 modified in function.array-unshift by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:52:05 +0000 |
| Subject: | note 23429 modified in function.array-unshift by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79754@lists.php.net to get a copy of this message | ||
A simpler way to implement an array_unshift with key=>value pairs (i.e. similar to the example
using array_reverse above) is to use array_merge. i.e.
<?php
$arrayone=array_merge(array("newkey"=>"newvalue"),$arrayone);
?>
Obviously you need to take care when adding numeric or duplicate keys.
--was--
A simpler way to implement an array_unshift with key=>value pairs (i.e. similar to the example
using array_reverse above) is to use array_merge. i.e.
$arrayone=array_merge(array("newkey"=>"newvalue"),$arrayone);
Obviously you need to take care when adding numeric or duplicate keys.
http://php.net/manual/en/function.array-unshift.php