我有PHP数组看起来像
$my_arr['cats'] = array('Shadow', 'Tiger', 'Luna');
$my_arr['dogs'] = array('Buddy', 'Lucy', 'Bella');
$my_arr['dolphins'] = array('Sunny', 'Comet', 'Pumpkin');
$my_arr['lizzards'] = array('Apollo', 'Eddie', 'Bruce');
//and many more lines like this
我需要使用排序数组来基于它来对它进行排序
$order = array('lizzards', 'cats');
我希望第一项应该是 lizzards 数组,第二项 - cats 然后是$ order数组中未指定的所有项 . 如何使用usort / uasort / uksort函数完成?
2 回答
您可以通过以下代码实现此目的
使用uksort的更短解决方案: