如何将 PHP 数组中的最后 n 项作为另一个数组获取? [英] How to get the last n items in a PHP array as another array?
本文介绍了如何将 PHP 数组中的最后 n 项作为另一个数组获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 PHP 中获取另一个数组的最后 n 项的数组?
How to I get an array of the last n items of another array in PHP?
推荐答案
$n
等于你想要结束的项目数.
$n
is equal to the number of items you want off the end.
$arr = array_slice($old_arr, -$n);
这篇关于如何将 PHP 数组中的最后 n 项作为另一个数组获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文