我的數組的值是以單個數字開始,然後增加到數以千計。PHP排序數組值爲0,1,2 ... 8,9,10,11,12等
我想排序的$ id,但有結果爲:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
....等
不
0,1,10,11,12,13,14,15,2,3,4,5,6,7,8,9
....等
是這可能沒有調整數組內的值?
謝謝:)
我的數組的值是以單個數字開始,然後增加到數以千計。PHP排序數組值爲0,1,2 ... 8,9,10,11,12等
我想排序的$ id,但有結果爲:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
....等
不
0,1,10,11,12,13,14,15,2,3,4,5,6,7,8,9
....等
是這可能沒有調整數組內的值?
謝謝:)
我覺得
natsort (array &$array)
是solution.From PHP手冊:
<?php
$array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png");
asort($array1);
echo "Standard sorting\n";
print_r($array1);
natsort($array2);
echo "\nNatural order sorting\n";
print_r($array2);
?>
The above example will output:
Standard sorting
Array
(
[3] => img1.png
[1] => img10.png
[0] => img12.png
[2] => img2.png
)
Natural order sorting
Array
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)
感謝您的幫助:) – JeffVader 2013-04-29 07:41:20
試一下:
sort($myarr, SORT_STRING);
顯示你當前的代碼。 – Nelson 2013-04-26 16:12:16
如果你只有一個ar數字的一線,是否有原因排序()不起作用? – 2013-04-26 16:12:34