There are two arrays:

$arr = [1,2,3,4,5] $var = [100,200,300,400,500] 

How to implement such a conclusion

 1 100 2 3 4 400 5 500 

Thank you, the input data may be different. Please do not customize this case.

Closed due to the fact that the essence of the question is incomprehensible by the participants Alexey Shimansky , aleksandr barakin , Vartlok , Vladimir Martyanov , Dmitriy Simushev 11 Apr '16 at 11:56 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 3
    Why it is not necessary to deduce 200, 300 after 2, 3? - Vasily Barbashev
  • To get an answer, explain exactly what you see the problem, how to reproduce it, what you want to get as a result, etc. Give a sample code. - Alexey Shimansky
  • one
    @ Mr.Nomov Duck, what is the condition of what does not need to be output after 2 and 3, 200 and 300, after how many indices will not need to be output the next time, after 6 and 7? - Vasily Barbashev
  • one
    Where did these arrays come from? - Ipatyev
  • 2
    homework? maybe you will formulate the task completely. it is still not clear why the 2nd and 3 are the beginning of a new ten , and 200 is not :) - splash58

2 answers 2

It is not clear by what principle you disappeared in output 200 and 300 from the second array. If you just need to sort by the "string" principle:

 $arr = [1,2,3,4,5]; $var = [100,400,500]; $sum = array_merge($arr,$var); sort($sum, SORT_STRING); print_r($sum); 

At the exit:

 Array ( [0] => 1 [1] => 100 [2] => 2 [3] => 3 [4] => 4 [5] => 400 [6] => 5 [7] => 500 ) 
  • You can mean again there are two arrays 1,1,1,2,2,3,3,3 and 11,22,33 how to display in this form the indices of the first array 0 1 2 the value 2 of the array 11 then the index 3 4 the value of the second array 22 further index 5 6 7 value 2 of the array 33 ??? - Mr. Nomov

In order to solve a problem, it is necessary to fully formulate it. You may know it completely, but we do not. It is completely unclear from the text of the question, according to which rules you arrange the order of elements from arrays.

For the solution you just need to sort through the arrays and set the conditions. For example, if the condition is great random:

 <?php $arr = [1,2,3,4,5]; $var = [100,200,300,400,500]; while(count($var) > 0 && count($arr) > 0){ echo array_shift($arr) + "<br>"; while(count($var) > 0){ if(rand(1,3) == 2) break; //привет, я условие рандом echo array_shift($var) + "<br>"; } } ?> 

You just need to substitute your values ​​/ order / additional conditions / maybe do something else, based on the full text of the task.

PS This code modifies the original arrays, if you do not want this, you will have to create variables with the current position and check whether it has crossed the array boundaries.