使用 " + "
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'
);
反过来 $someArray = $someArray + array(100=>'Test Element 1 ',255=>'Test Element 2');
输出:
array(
224=>'someword1',
228=>'someword2',
102=>'someword3',
544=>'someword3',
95=>'someword4' ,
100=>'Test Element 1 ',
255=>'Test Element 2'
);
来源:http://php.net/manual/zh/function.array-unshift.php