我有一个如下所示的数组:
$names = array('joey','kaiba','marik','yugi');
我想颠倒这个数组中元素的顺序,它们看起来像这样:
$names = array('yugi','marik','kaiba','joey');
是否有现成的PHP函数可以让我这样做?
答案 0 :(得分:0)
php提供的内置函数是array_reverse()
<?php
$names = array('joey','kaiba','marik','yugi');
print_r(array_reverse($names));
?>
答案 1 :(得分:0)
$names = array('joey','kaiba','marik','yugi');
$names=array_reverse($names);
答案 2 :(得分:0)
PHP函数array_reverse()完全符合您的要求:
$names = array('joey','kaiba','marik','yugi');
$reversed = array_reverse($names);
print_r($reversed);
输出:
Array (
[0] => yugi
[1] => marik
[2] => kaiba
[3] => joey
)