如何适用ksort
于数组的每个元素$counts
?我的意思是简单地在每个嵌套数组上调用这个函数,而不是递归。
bool array_walk(array &$array, callable $funcname [,mixed $userdata = NULL])
我试过array_walk
将标志SORT_NUMERIC
作为用户数据传递。这给了我一个警告:
$counts = array();
$counts['group1'] = array(); // Keys are timestamps but as STRING
$counts['group2'] = array(); // Keys are timestamps but as STRING
// ...
// Array + operator does a key reordering here
$counts['group1'] += $dummyData;
$counts['group2'] += $dummyData;
// .. so sort array by keys
array_walk($counts, 'ksort', SORT_NUMERIC);
警告: ksort() 最多需要 2 个参数,给定 3 个。
第三个参数是什么?
编辑:天才答案:
foreach($counts as &$group) :
ksort($group, SORT_NUMERIC);
endforeach;