下面是我的数组,我想根据[属性] - > [0] - > [value]对其进行排序 我怎么能这样做,请指导我。 我尝试使用排序,但如何让它适用于子数组的值。 请指导我新的。
[549246] => Array
(
[info] => Array
(
[price] => $281.00
[qty] => 10
[prod_id] => 549246
)
[attributes] => Array
(
[0] => Array
(
[code] => sizes
[label] => Size
[value] => 25mg
[attribute_id] => 191
[option_id] => 26
)
)
)
[549245] => Array
(
[info] => Array
(
[price] => $75.00
[qty] => 10
[prod_id] => 549245
)
[attributes] => Array
(
[0] => Array
(
[code] => sizes
[label] => Size
[value] => 5mg
[attribute_id] => 191
[option_id] => 24
)
)
)
答案 0 :(得分:1)
尝试以下;
function customer_sort ($a, $b) {
if ((int)$a['attributes'][0]['value'] == (int)$b['attributes'][0]['value']) {
return 0;
}
return (int)$a['attributes'][0]['value'] > (int)$b['attributes'][0]['value'] ? 1 : -1;
}
uasort($arr, 'customer_sort');