Deep parsing of PHP array functions array_slice

Source: Internet
Author: User

Seeing Array_slice () is a function that reminds me of the range value clause in VFP.

This function has a total of four parameters:

Array to be evaluated (required)

Starting position of the value (required)

The terminating position of the value, if not filled in by default to the last element of the array (optional)

Whether to retain the original key name (optional)

This function can be used as a paging operation

1. When the value range is positive (starting from the first element in the array, take two elements)

<?Php$arr= Array ('a','b','C','D'); $ret= Array_slice ($arr,1,2);p Rint_r ($ret);//Run resultArray ([0] =b [1] =c)

2. When the value starting range is negative, the number of values is positive

When the starting position of the value is negative, it is counted from the end of the element, and then the value

<? PHP $arr Array (' A ', ' B ', ' C ', ' d ', ' e '); $ret Array_slice ($arr, -2,2); Print_r ($ret); // Run result Array (    [0] = + d    [1] = e)

3. Do you want to leave the original key name here? No example is done.

This article for fennel dumplings Blog original, welcome reprint, reproduced please indicate the source

Fennel Dumplings Blog http://www.cnblogs.com/hxjz/

Deep parsing of PHP array functions array_slice

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.