我得到了这个数组:
Array
(
[0] => Array
(
[_complex] => 1
[_attributes] => Array
(
[id] => 453
)
[_data] => Array
(
[id] => 453
[nid] => lastname
)
)
[1] => Array
(
[_complex] => 1
[_attributes] => Array
(
[id] => 455
)
[_data] => Array
(
[id] => 455
[nid] => lastname
)
)
如何按[_data][nid]
对其进行排序?
答案 0 :(得分:1)
uasort(
$array,
function ($a,$b) {
return strcmp($a['_data']['nid'],$b['_data']['nid']);
}
);
答案 1 :(得分:0)
数组中的ID是否始终相同?那你为什么不把它转换成这样的东西:
Array
(
[0] => Array
(
[_complex] => 1
[id] => 453
[nid] => lastname
)
[1] => Array
(
[_complex] => 1
[id] => 455
[nid] => lastname
)
)
或者有没有理由不这样做?这将更容易排序,更容易处理。转换它时,您可以使用此功能:
aasort($your_Array, "nid");
function aasort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
asort($sorter);
foreach ($sorter as $ii => $va) {
$ret[$ii]=$array[$ii];
}
$array=$ret;
}