我有两个数组
Array
(
[0] => stdClass Object
(
[id] => 1
[title] => art
)
[1] => stdClass Object
(
[id] => 4
[title] => adsdf
)
[2] => stdClass Object
(
[id] => 2
[title] => adsdf
)
[3] => stdClass Object
(
[id] => 7
[title] => adsdf
)
)
Array
(
[2] => 2
[1] => 1
)
我想把第一个数组排在第二个数组之后。在第二个数组中,键和值与第一个数组id相等。因此输出必须如下所示:
Array
(
[0] => stdClass Object
(
[id] => 2
[title] => adsdf
)
[1] => stdClass Object
(
[id] => 1
[title] => art
)
[2] => stdClass Object
(
[id] => 4
[title] => adsdf
)
[3] => stdClass Object
(
[id] => 7
[title] => adsdf
)
)
您可以使用array_multisort
<一口>[医生]一口>:
array_multisort($arraySort, $arrayData);
将排序顺序作为第一个参数传递数组,将要排序的数组作为第二个参数传递。
你可能需要在它之前构建排序数组,从你的问题来看,我不清楚你是否已经拥有它。
如果不是,如果您希望将所有数据数组项的ID值放入排序数组中:
$arraySort = array();
foreach($arrayData as $key => $obj)
{
$arraySort[$key] = $obj->id;
}