Home  >  Article  >  Backend Development  >  How to get the first few data from php array

How to get the first few data from php array

L
LOriginal
2020-06-01 15:34:245917browse

How to get the first few data from php array

array_slice() function removes a segment of value from the array based on conditions and returns it.

Syntax: array_slice(array,start,length,preserve)

Get the first 4 digits of the array

array_slice($arr,0,4);

Get the last 4 digits of the array

array_slice($arr,-4,4);

or

array_slice($arr,-4);

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of How to get the first few data from php array. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn