Problem merging/sorting arrays in PHP
I have 3 arrays like开发者_如何学JAVA so, that can contain an infinite number of items:
Weight Array ( [0] => 20 [1] => 250 [2] => 400 )
Price Array ( [0] => 1.20 [1] => 6.00 [2] => 9.50 )
Courier Array ( [0] => DHL [1] => DHL [2] => UPS )
I'd like to merge them and sort them like so:
Array (
[0] => 20
[1] => 1.20
[2] => DHL
[3] => 250
[4] => 6.00
[5] => DHL
[6] => 400
[7] => 9.50
[8] => UPS
)
Is there a built in PHP function that does this or will I have to write my own?
There is no need in function, I suppose:
for ($i=0; $i<count($WeightArray); $i++) {
$TargetArray[] = $WeightArray[$i];
$TargetArray[] = $PriceArray[$i];
$TargetArray[] = $CourierArray[$i];
}
There is indeed one built-in.
http://us3.php.net/array_merge
$newarray = array_merge($array1,$array2);
This should do the trick, you can add as many parameters as you want to add more arrays.
精彩评论