Im trying to sort an multidimentional array based on a array in the order i would like it to appear in.
the $lookingfor
array contains the order i would like it to appear, while $avaliableArray
contains the whole multidimentional array. Would like the result in the example code called $resultarray
How would i do this, based on the id
of the elements in $avaliableArray
?
code:
$avaliableArray = array(
array('name' => 'Banken', 'site' => 'bank', 'avaliable' => true, 'type' => 'site', 'id' => "testid-1"),
array('name' => 'Banken', 'site' => 'bank', 'avaliable' => true, 'type' => 'site', 'id' => "testid-4"),
array('name' => 'Banken', 'site' => 'bank', 'avaliable' => true, 'type' => 'site', 'id' => "testid-8")
);
$lookingFor = array(1,8,4);
looking for result:
$resultArray = array(
array('name' => 'Banken', 'site' => 'bank', 'avaliable' => true, 'type' => 'site', 'id' => "testid-1"),
array('name' => 'Banken', 'site' => 'bank', 'avaliable' => true, 'type' => 'site', 'id' => "testid-8"),
array('name' => 'Banken', 'site' => 'bank', 'avaliable' => true, 'type' => 'site', 'id' => "testid-4")
);