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
$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;
});
try this
$array = array_merge($array1,$array2,$array3); //you can pass multiple array
asort($array);
print_r($array);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.