Reputation: 27
I have three arrays:
$arr1=array(0,5,2,3,4,5);
$arr2=array(0,5,2,3,4,5);
$arr3=array(0,5,2,3,4,5);
I want to store their value in 4th array like below:
$arr4=array(0,0,0,5,5,5,2,2,2,3,3,3,4,4,4,5,5,5);
pls input
Upvotes: 0
Views: 1034
Reputation: 3679
$arr4 = array_merge($arr1, $arr2, $arr3);
asort($arr4);
EDIT
Sorry. asort
doesn't sort the way you want.
You can use a callback for sorting, but this works only if every of your input arrays has the same element count.
$arr4 = array_merge($arr1, $arr2, $arr3);
$length = count($arr1);
uksort($arr4, function($k1, $k2) use($length) {
$sort = $k1%$length - $k2%$length;
if ($sort == 0) $sort = floor($k1/$length) - floor($k2/$length);
return $sort;
});
Upvotes: 1
Reputation: 8848
try this
$array = array_merge($array1,$array2,$array3); //you can pass multiple array
asort($array);
print_r($array);
Upvotes: 1