0

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

0

2 Answers 2

1

try this

$array = array_merge($array1,$array2,$array3); //you can pass multiple array 
asort($array);
print_r($array);
Sign up to request clarification or add additional context in comments.

1 Comment

@stefandoorn ellipse is the indication of number of argument can be passed
1
$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;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.