echo '<pre>'.print_r($listings,1).'</pre>';
ksort($listings, SORT_NUMERIC);
echo '<pre>'.print_r($listings,1).'</pre>';
Run Code Online (Sandbox Code Playgroud)
输出:
Array
(
[quick-brown-fox] => Array
(
[0] => Quick-brown-fox
[1] => quick-brown-fox
[4] => general_thumbs/quick-brown-fox.jpg
[2] => 320
[3] => 240
)
)
Array
(
[quick-brown-fox] => Array
(
[0] => Quick-brown-fox
[1] => quick-brown-fox
[4] => general_thumbs/quick-brown-fox.jpg
[2] => 320
[3] => 240
)
)
Run Code Online (Sandbox Code Playgroud)
我试过了foreach,但是它不会影响原始数组,for也不会起作用,因为它是键,而不是索引。在这种情况下我该怎么办?
您已在该$listings数组中嵌套了数组。对其进行排序,如下所示:
foreach($listings as $k => $a){
ksort($a, SORT_NUMERIC);
$listings[$k] = $a;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2774 次 |
| 最近记录: |