Home > Backend Development > PHP Tutorial > Usage Analysis of Negative Limit of Explode in PHP_PHP Tutorial

Usage Analysis of Negative Limit of Explode in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:05:54
Original
763 people have browsed it

Analysis on the usage of negative limit in explode in php

This article mainly introduces the usage of negative limit in explode in php, and an example analysis of the usage of negative limit parameter in explode, which has certain For reference value, friends in need can refer to it

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:

?

1

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

1
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:

1

2

$str="1 2 3 4 5 6";

print_r(explode(" " ,$str,-2));

?

1

2

$str="1 2 3 4 5 6";

1

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

print_r(explode(" " ,$str,-2));

will see:

? 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.
http://www.bkjia.com/PHPjc/961776.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/961776.htmlTechArticleUsage Analysis of Negative Limit of Explode in PHP This article mainly introduces the usage of negative limit of explode in PHP, and example analysis The usage of negative limit parameter in explode has certain reference value...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template