Home >Backend Development >PHP Tutorial >Usage analysis of negative limit of explode in PHP, explodelimit_PHP tutorial

Usage analysis of negative limit of explode in PHP, explodelimit_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:05:57785browse

Usage analysis of negative limit in explode in php, explodelimit

The example in this article describes the usage of negative limit of explode in php. Share it with everyone for your reference. The specific analysis is as follows:

explode -- Use one string to split another string into an array.
The parameters are:

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

The last limit does not need to be filled in. At this time, the string will be divided according to the separator separator; if the limit is filled with a positive number, it will be divided into (limit+1) numbers from left to right, and if it is a negative number, it will be divided from the right Remove the limit array elements (the parameter is negative starting from php5.1), leaving the remaining parts to form an array.

For example:

$str="1 2 3 4 5 6";
print_r(explode(" " ,$str,-2));

will see:

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

It can be seen that the two elements 5 and 6 have been deleted.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/961390.htmlTechArticleAnalysis on the usage of negative limit of explode in php, explodelimit This article describes the usage of negative limit of explode in php. Share it with everyone for your reference. The specific analysis is as follows: explode -- use...
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