<pre><span style="font-size: 15px;">//原始数组是这样的,希望能够按照第二维中的run_date升序或者降序进行排序:
2 $arr=array(
3 0=>array(
4 'run_date'=>'2017-11-21',
5 'count'=>'5'
6 ),
7 1=>array(
8 'run_date'=>'2017-11-20',
9 'count'=>'10'
10 ),
11 2=>array(
12 'run_date'=>'2017-11-22',
13 'count'=>'10'
14 )
15 );</span><br /><br /><span style="font-size: 15px;">
16 //希望得到:
17 $arr=array(
18 0=>array(
19 'run_date'=>'2017-11-20',
20 'count'=>'5'
21 ),
22 1=>array(
23 'run_date'=>'2017-11-21',
24 'count'=>'10'
25 ),
26 2=>array(
27 'run_date'=>'2017-11-22',
28 'count'=>'10'
29 )
30 );</span><br /><br /><br /><span style="font-size: 15px;">|----------------------------------------开始------------------------------------------------------------|</span></pre>
<pre><span style="font-size: 15px;"><span style="background-color: #99ccff;">//先用<span style="font-family: 宋体; font-size: 18px; color: #ff0000;">array_column</span> 多维数组按照纵向(列)取出</span>
<strong><span style="color: #000000; font-size: 18px;">$date = array_column($arr, 'run_date');</span></strong>
//上面得到的结果:array(0=>'2017-11-21',1=>'2017-11-20',3=>'2017-11-22')
<span style="background-color: #99ccff;">//再用<span style="color: #ff0000;">array_multisort</span> 结合array_column得到的结果对$arr进行排序</span>
<span style="font-size: 18px;"><strong>array_multisort($date,SORT_ASC,$arr);</strong></span>
//最终的结果:
$arr=array(
0=>array(
'run_date'=>'2017-11-20',
'count'=>'5'
),
1=>array(
'run_date'=>'2017-11-21',
'count'=>'10'
),
2=>array(
'run_date'=>'2017-11-22',
'count'=>'10'
)
);</span></pre>
<pre><br /><br /><br /><br /><br /><br /><br /></pre>