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

查看:61
本文介绍了从数组返回前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天全站免登陆