Define and use the array_slice () function in the PHP array
The array_slice () function extracts a value from the array based on the conditions and returns it.
Note: If the array has a string key, the returned array retains the key name. (See example 4)
Syntax
Array_slice (array, offset, length, preserve)
Parameters
Array
Required. Specifies the input array.
Offset
Required. Value. Specifies the start position of the retrieved element. If it is a positive number, it is taken from the beginning to the end. if it is a negative value, it is taken from the back to the absolute value of the offset.
Length
Optional. Value. Specifies the length of the returned array. If the length is positive, the number of elements is returned. If length is negative, the sequence ends so far from the end of the array. If this parameter is omitted, the sequence starts from offset to the end of array.
Preserve
Optional. Possible values:
True-reserved key
False-default-reset key
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service