数组上的 php sort() 产生错误的结果 [英] php sort() on array produces wrong result
本文介绍了数组上的 php sort() 产生错误的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对一个看起来像这样的数组进行排序(按数字顺序而不是 1、10、11):
I want to sort an array that looks like this (to numerical order instead of 1, 10, 11):
Array ( [0] => 1.jpg [1] => 10.jpg [2] => 11.jpg [3] => 111.jpg [4] => 12.jpg [5] => 12a.jpg [6] => 13.jpg [7] => 14.jpg [8] => 15.jpg [9] => 16.jpg [10] => 2.jpg [11] => 3.jpg [12] => 4.jpg [13] => 5.jpg [14] => 6.jpg [15] => 7.jpg [16] => 8.jpg [17] => 9.jpg )
当我使用 sort() 时,它只是变成了1"而不是一个已排序的数组.
when i use sort() it just becomes "1" instead of a sorted array.
代码:
$this->pageLinks = sort($this->pageLinks); // the array is a property in a class
print_r($this->pageLinks); // want to display the sorted array here but it just returns 1
推荐答案
sort()
就地对数组进行排序.不要重新分配它.
sort()
sorts the array in-place. Don't re-assign it.
sort($this->pageLinks);
不正确:
$this->pageLinks = sort($this->pageLinks);
这篇关于数组上的 php sort() 产生错误的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文