note 78238 modified in function.array-unshift by danbrown

From: Date: Wed, 12 Aug 2009 16:39:03 +0000
Subject: note 78238 modified in function.array-unshift by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159378@lists.php.net to get a copy of this message
You can preserve keys and unshift an array with numerical indexes in a really simple way if you'll do the following: <?php $someArray=array(224=>'someword1', 228=>'someword2', 102=>'someword3', 544=>'someword3',95=>'someword4'); $someArray=array(100=>'Test Element 1 ',255=>'Test Element 2')+$someArray; ?> now the array looks as follows: array( 100=>'Test Element 1 ', 255=>'Test Element 2' 224=>'someword1', 228=>'someword2', 102=>'someword3', 544=>'someword3', 95=>'someword4' ); --was-- You can preserve keys and unshift an array with numerical indexes in a really simple way if you'll do the following: $someArray=array(224=>'someword1', 228=>'someword2', 102=>'someword3', 544=>'someword3',95=>'someword4'); $someArray=array(100=>'Test Element 1 ',255=>'Test Element 2')+$someArray; now the array looks as follows: array( 100=>'Test Element 1 ', 255=>'Test Element 2' 224=>'someword1', 228=>'someword2', 102=>'someword3', 544=>'someword3', 95=>'someword4' ); http://php.net/manual/en/function.array-unshift.php

« previous php.notes (#159378) next »