我正在尝试对以下数组进行排序,但由于某些奇怪的原因,它似乎无法正常工作
$sizearray = Array (
[0] => 39
[1] => 40
[2] => 41
[3] => 42
[4] => 43
[5] => 44
[6] => 45
[7] => 39
[8] => 40
[9] => 41
[10] => 42
[11] => 43
[12] => 44
[13] => 45
[14] => 39
[15] => >40
[16] => 41
[17] => 42
[18] => 43
[19] => 44
[20] => 45
);
$sizearray = array_values(sort(array_unique($sizearray)));
以下警告显示:
>Warning: array_values() [function.array-values]: The argument should be an array in
>/home/starlet/public_html/productlist.php on line 349
注意:如果我删除sort()
函数,array_values()
函数运行正常。
答案 0 :(得分:1)
那是因为sort
就位并返回一个布尔值。
来自the docs:
bool sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
你可能需要做这样的事情:
$sizearray = array_unique($sizearray);
sort($sizearray);
$sizearray = array_values($sizearray);
答案 1 :(得分:1)
答案 2 :(得分:0)
<?php
$fruits = array(
"Orange1", "orange2", "Orange3", "orange20"
);
sort($fruits, SORT_NATURAL | SORT_FLAG_CASE);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
The above example will output:
fruits[0] = Orange1
fruits[1] = orange2
fruits[2] = Orange3
fruits[3] = orange20