我有两个多维数组,需要根据不同的键以与第二个数组相同的顺序对第一个数组进行排序(但它们的值相同)。在下面的示例中,我需要按照与 的值相同$allOptions的顺序进行排序。$regOptionsclID == optID
但是,并非所有$allOptions子数组 (clID) 都存在于$regOptions子数组 (optID) 中......因此,其中任何不匹配的元素都$allOptions将被扔到数组的底部/末尾。
我怎样才能做到这一点?
$allOptions = array(
array("clID"=> 171, ...other values),
array("clID"=> 191, ...other values),
array("clID"=> 131, ...other values),
array("clID"=> 101, ...other values),
array("clID"=> 201, ...other values),
array("clID"=> 181, ...other values),
...
array("clID"=> 99, ...other values), // not in regOptions
array("clID"=> 129, ...other values) // not in regOptions
array("clID"=> 139, ...other values)
) ;
$regOptions = array(
array("order"=>1,"optID"=> 131, ...other values),
array("order"=>2,"optID"=> 191, ...other …Run Code Online (Sandbox Code Playgroud)