I have two multi dimensional arrays here:- one which is having the order
$order = [1=>'apple', 2=>'banana', 3=>'mango'];
Another array in which i have the data to be sorted:
$data = [
['title'=>'fruit', 'name'=>'banana'],
['title'=>'fruit', 'name'=>'apple'],
['title'=>'fruit', 'name'=>'mango'],
['title'=>'fruit', 'name'=>'pineapple'],
];
There are values whose order in not mentioned in the $order
array so they can come underneath the rest of the array values as given in the result below:
After sorting i should be getting the result as :
[
['title'=>'fruit', 'name'=>'apple'],
['title'=>'fruit', 'name'=>'banana'],
['title'=>'fruit', 'name'=>'mango'],
['title'=>'fruit', 'name'=>'pineapple']
];
I have gone through many answers in SO but couldn't even begin with such a scenario; 1. How do I Sort a Multidimensional Array in PHP 2. Sort PHP multi-dimensional array based on value in inner array?