列在最深的子阵列中的列中的3D数组的父级

问题描述 投票:0回答:2
我需要按

ref_no

以降序排序以下数组。例如:在位置
[0]
应该有id
16
(因为它的
ref_no
较大)和ind的属性
[1]
10
主数组的大小是动态的,属性数组的大小保持不变。
    

apply

$array = [ [ 'Property' => ['id' => 10, 'member_id' => 2, 'ref_no' => 333] ], [ 'Property' => ['id' => 16, 'member_id' => 4, 'ref_no' => 509] ] ];

php arrays sorting multidimensional-array
2个回答
2
投票

usort


                

usort($input, function ($a, $b) {return ($a['ref_no']>$b['ref_no']);});
的回调中,比较存在下面的
usort()

0
投票
ref_no

(太空飞船操作员)的右侧,您可以实现下降。无论

Property
值是字符串型还是int-type,太空飞船操作员仍然将它们作为整数(数值,而不是词典)进行比较。 demo

$b
	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.