Php 排序数组有错误,没有英文键
我有一个这样的数组 我必须按价值排序 数组键是非英语的 33必须在第一个和24,10和7等 但是当我使用sort、asort或uksort时,它只返回1Php 排序数组有错误,没有英文键,php,arrays,sorting,Php,Arrays,Sorting,我有一个这样的数组 我必须按价值排序 数组键是非英语的 33必须在第一个和24,10和7等 但是当我使用sort、asort或uksort时,它只返回1 1 使用非英语语言作为键的这些函数和数组是否有任何问题 代码: 好的,让我们看看: $nextArray = array_count_values($arr1); // this is an array $nextArray = sort($nextArray); // as *sort function retu
1
使用非英语语言作为键的这些函数和数组是否有任何问题
代码:
好的,让我们看看:
$nextArray = array_count_values($arr1); // this is an array
$nextArray = sort($nextArray); // as *sort function return bool you overwrite array value with bool value
print_r($nextArray);
正确的代码应为:
$nextArray = array_count_values($arr1);
sort($nextArray);
print_r($nextArray);
*排序函数返回布尔值,而不是数组。你知道吗?不知道!但是打印后不要返回任何东西!您可以阅读php中的排序;然后,您可能需要获得预期的排序,您使用什么样的代码来排序和打印?
$nextArray = array_count_values($arr1); // this is an array
$nextArray = sort($nextArray); // as *sort function return bool you overwrite array value with bool value
print_r($nextArray);
$nextArray = array_count_values($arr1);
sort($nextArray);
print_r($nextArray);