我有一个数组
Array ( [0] => elem0 [1] => elem1 [2] => elem2 [3] => elem3 [4] => elem4 )
我想从数组中取出最后两个元素并替换该数组的开头。
获得:
Array ( [0] => elem3 [1] => elem4 [2] => elem0 [3] => elem1 [4] => elem2 )
在 PHP 中。
编辑
我发现 :
$pkeys= Array ( [0] => elem0 [1] => elem1 [2] => elem2 [3] => elem3 [4] => elem4 );
$output = array_slice($pkeys, -2, 2);
array_splice($pkeys, -2, 2);
$pkeys=array_merge($output,$pkeys);
print_r ($pkeys);
结果 :
Array ( [0] => elem3 [1] => elem4 [2] => elem0 [3] => elem1 [4] => elem2 )
没关系!