I'm new to php and have been trying to sort a 2d array of strings, with a specific order array. Have been looking at using 'usort' and 'comparison', but cant seem to wrap my head around them when using 2d array and strings.
Need to input array to method and return sorted array, with same format. So for each entry in array it will sort the 2nd level 'file' value dependant on the order of order array. Any suggestions how to accomplish this?
//actual array to be sorted by 'file'
$Array (
[0] => Array ( [source] => img/table/icon/toxic.svg [file] => toxic )
[1] => Array ( [source] => img/table/icon/health.svg [file] => health )
[2] => Array ( [source] => img/table/icon/irritant.svg [file] => irritant ));
//order array with desired sort order
$order = array("irritant","corrosive","environment" ,"health","toxic","oxidizing","flammable","explosive","gas");
//Desired Output Result
$Array (
[0] => Array ( [source] => img/table/icon/irritant.svg [file] => irritant )
[1] => Array ( [source] => img/table/icon/health.svg [file] => health )
[2] => Array ( [source] => img/table/icon/toxic.svg [file] => toxic ) );
See so irritant is first and toxic is last :)