Negative limit usage analysis of explode in PHP _php tips

Source: Internet
Author: User
Tags explode

This example describes the negative limit usage of explode in PHP. Share to everyone for your reference. The specific analysis is as follows:

Explode--use one string to split another string to make it an array.
Parameters are:

Array explode (string separator, string string [, int limit])

The final limit can not fill, at this time will be divided into the separator string all the light, if the limit filled with positive numbers, then split from left to right (limit+1) each number, if it is negative, then remove the limit array elements from the right ( The parameter is negative starting from php5.1), leaving the remaining parts to form an array.

Such as:

$str = "1 2 3 4 5 6";
Print_r (Explode ("", $str,-2));

You will see:

Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4)

Visible 5, 62 elements are removed.

I hope this article will help you with your PHP program design.

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.