我在下面给出了数组,我希望按级别值1到4对该数组进行排序。
表格:
Array ( [20] => Array ( [sid] => 1020 [L] => 1027 [R] => 1033 [Level] => 1 )
[27] => Array ( [sid] => 1027 [L] => 1030 [R] => 1073 [Level] => 2 )
[30] => Array ( [sid] => 1030 [L] => 1074 [R] => [Level] => 3 )
[74] => Array ( [sid] => 1074 [L] => [R] => [Level] => 4 )
[73] => Array ( [sid] => 1073 [L] => [R] => [Level] => 3 )
[33] => Array ( [sid] => 1033 [L] => [R] => [Level] => 2 ) )
要
Array ( [20] => Array ( [sid] => 1020 [L] => 1027 [R] => 1033 [Level] => 1 )
[27] => Array ( [sid] => 1027 [L] => 1030 [R] => 1073 [Level] => 2 )
[33] => Array ( [sid] => 1033 [L] => [R] => [Level] => 2 )
[30] => Array ( [sid] => 1030 [L] => 1074 [R] => [Level] => 3 )
[73] => Array ( [sid] => 1073 [L] => [R] => [Level] => 3 )
[74] => Array ( [sid] => 1074 [L] => [R] => [Level] => 4 )
)
答案 0 :(得分:2)
您可以使用array_multisort()
<?php
$array = array(
array('Level'=>1),
array('Level'=>2),
array('Level'=>3),
array('Level'=>4),
array('Level'=>3),
array('Level'=>2)
);
$tmp = array();
foreach($array as $r){
$tmp[] = $r['Level'];
}
array_multisort($tmp,SORT_ASC,$array);
echo '<pre>',print_r($array),'</pre>';