从数组中返回前 x 项 [英] Returning first x items from array

查看:16
本文介绍了从数组中返回前 x 项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数组中返回前 5 个项目.我该怎么做?

I want to return first 5 items from array. How can I do this?

推荐答案

array_slice返回一个数组的切片

array_slice returns a slice of an array

$sliced_array = array_slice($array, 0, 5)

是您希望在您的案例中返回前五个元素的代码

is the code you want in your case to return the first five elements

这篇关于从数组中返回前 x 项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆