我在foreach函数上使用PHP
$arr = array(array(1,2,3,4,5,6,7,8,9,10));
foreach($arr as $item){
var_dump($item);
}
这是我的结果
array (size=10)
0 => int 1
1 => int 2
2 => int 3
3 => int 4
4 => int 5
5 => int 6
6 => int 7
7 => int 8
8 => int 9
9 => int 10
但是我想从高到小逆转
array (size=10)
0 => int 10
1 => int 9
2 => int 8
3 => int 7
4 => int 8
5 => int 9
6 => int 4
7 => int 5
8 => int 2
9 => int 1
我该怎么办
答案 0 :(得分:1)
您可以使用PHP反向数组排序(rsort)。请参阅Documentation
$arr = array(array(1,2,3,4,5,6,7,8,9,10));
rsort($arr);
foreach($arr as $item){
var_dump($item);
}
答案 1 :(得分:1)
使用array_reverse():
$arr = array(array(1,2,3,4,5,6,7,8,9,10));
foreach($arr as $item){
var_dump(array_reverse ($item));
}
请参阅result