嗨,有人可以帮我按另一个数组排序多维数组吗?
数组1:
Array(
[0] => Array(
'id' => '58e9f01ff291c'
),
[1] => Array(
'id' => '58e9f0590d6c0'
),
[2] => Array(
'id' => '58ea5274219ac
)
)
数组2:
Array('58e9f0590d6c0', '58ea5274219ac', '58e9f01ff291c')
第二个数组包含第一个数组的ID,我想按第二个数组中的ID对第一个数组进行排序。我怎么能这样做?
祝愿和感谢任何帮助
罐头
更新
我明白了:
$return = array();
foreach($array2 as $sortId) {
foreach ($array1 as $subKey => $subArray) {
if ($subArray['id'] == $sortId) {
$return[] = $array1[$subKey];
break;
}
}
}