0

Here I can't find a solution to sort the two arrays in this order?

I have two arrays. arr_1 = [66/11,67/11,66/12] arr_2 = [66/13,67/12] The result must be in a way that if 66 is first pushed to array.Then we must check the whole array if it contains 66 if not found, we can move to next value,here it is 67. If not we must move to arr_2 and array push 66 from it and if here we have 66 we should array push this to the result. Result must be like result=[66/11,67/11,67/12,66/12,66/13] The code i have tried is this $arr_1 = array(66,67,66); $arr_2 =array(66,67); $count_1=count($arr_1); $count_2=count($arr_2); $res=[]; for($i=0;i<$count;$i++){ if(in_array($arr_1[0],$arr_1){ array_push($res,$arr_1[0])} } ;

30th Nov 2022, 12:32 PM
Alan Ambrose
4 Answers
+ 3
Obviously I have a difficulty with understanding your English, because it is still not clear to me, what you are trying to do. Somehow combining the two arrays in a certain order... I see that you copied some code into your question. Well I tried it too, but it doesn't work. It has lots of syntax errors. You forget to use $ sign in front of variable names. You are not taking into account the size of either array in your for loop. You are not utilizing your loop variable.
1st Dec 2022, 7:00 AM
Tibor Santa
Tibor Santa - avatar
0
Your description is very confusing, I really don't understand WHAT you want to achieve, but you have pretty much already written in detail, HOW you want to achieve it. So just copy your own text... Add a few line breaks at the end of every half sentence... change "check" to "if" statements, and wrap it in a "for" loop. Help on PHP: Array indexing https://www.w3schools.com/php/php_arrays_indexed.asp Appending to an array https://www.w3schools.com/php/func_array_push.asp
30th Nov 2022, 7:15 PM
Tibor Santa
Tibor Santa - avatar
0
I have 2 arrays. array_1 = [66, 67,66] array_2 = [66, 67] The result must be in a way that if 66 is first pushed to array.Then we must check the whole array if it contains 66 if not found, we can move to next value,here it is 67. If not we must move to array_2 and array push 66 from it and if here we have 66 we should array push this to the result. Result must be like res=[66,67,67,66,66] ![More details in pic](https://i.stack.imgur.com/4bYC1.jpg)
30th Nov 2022, 11:57 PM
Alan Ambrose
0
What about this arrays. $a1=[1,1,1,2,2,3] $a2=[1,1,2,4]
1st Dec 2022, 7:22 AM
Alan Ambrose