Let's say you have two arrays of arrays with the same structure, but they have several array counters:
$arr1 = array(array(1,"b"), array(2,"a"), array(5,"c")); $arr2 = array(array(3,"e"));
Now the data in $ arr1 and $ arr2 are sorted, and now I would like to combine these two arrays, so I did this:
$res = array_merge($arr1, $arr2);
And then I get the output as follows:
1-b 2-a 5-c 3-e
But I would like the sorted $ res to also look like this:
1-b 2-a 3-e 5-c
I wonder if there is a function in PHP for this automatically, without having to write your own function? Or please tell me why this is the best approach for this, if I want (later) to add sorting by the following parameter, so that the result is like this:
2-a 1-b 5-c 3-e
Thank you for your help.
source share