我有一个数组里面有一些其他的数组:
如果我print_r($u)
,我得到:
Array
(
[0] => Albany
)
Array
(
[0] => Albany
Array
(
[0] => Albany
[41] => Albuquerque
)
Array
(
[0] => Albany
[41] => Albuquerque
)
Array
(
[0] => Albany
[41] => Albuquerque
[54] => Atlanta
)
Array
(
[0] => Albany
[41] => Albuquerque
[54] => Atlanta
)
Array
(
[0] => Albany
[41] => Albuquerque
[54] => Atlanta
[93] => Auckland
[94] => Augusta
)
Array
(
[0] => Albany
[41] => Albuquerque
[54] => Atlanta
[93] => Auckland
[94] => Augusta
)
...
最后一个数组大约有20个元素。我只需要最后一个数组。
您可以使用end()
函数:
$last_array = end($u);
请记住,调用end()
将改变内部数组指针。如果你不希望发生这种情况,你可以这样做:
$last_array = $u[count($u) - 1]; // make sure count($u) > 0
如果您只想从数组$u
中获取最后一项,您可以使用end
函数(无论其类型是什么):
$lastarray = end($u);
$arr = array_slice($u, -1);
呢?(将返回一个只包含您想要的数组的数组)还是$arr = array_pop($u)
?