如何通过"order"键的值对此数组进行排序?尽管这些值目前是连续的,但它们并不总是如此.
Array
(
[0] => Array
(
[hashtag] => a7e87329b5eab8578f4f1098a152d6f4
[title] => Flower
[order] => 3
)
[1] => Array
(
[hashtag] => b24ce0cd392a5b0b8dedc66c25213594
[title] => Free
[order] => 2
)
[2] => Array
(
[hashtag] => e7d31fc0602fb2ede144d18cdffd816b
[title] => Ready
[order] => 1
)
)
Run Code Online (Sandbox Code Playgroud) 我有两个多维数组,需要根据不同的键以与第二个数组相同的顺序对第一个数组进行排序(但它们的值相同)。在下面的示例中,我需要按照与 的值相同$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)