我的代碼是:二維數組排序使用PHP
$arr = array(
array(
"title" => "Volvo"
),
array(
"title" => "BMW"
),
array(
"title" => "Saab"
),
array(
"title" => "Aam"
)
);
$a = aasort($arr,"title");
echo "<pre>",print_r($a),"</pre>";
function aasort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
natcasesort($sorter);
foreach ($sorter as $ii => $va) {
$ret[$ii]=$array[$ii];
}
$array=$ret;
return $array;
}
,輸出是:
Array
(
[3] => Array
(
[title] => Aam
)
[1] => Array
(
[title] => BMW
)
[2] => Array
(
[title] => Saab
)
[0] => Array
(
[title] => Volvo
)
)
1
但我想輸出,如:
Array
(
[0] => Array
(
[title] => Aam
)
[1] => Array
(
[title] => BMW
)
[2] => Array
(
[title] => Saab
)
[3] => Array
(
[title] => Volvo
)
)
1
怎麼做?
什麼問題呢?任何消除?還是我們想要猜測? – NoLiver92
是的,我正在嘗試做?任何幫助表示讚賞。 –
看看'array_values' – msfoster