Home > Backend Development > PHP Tutorial > php中explode的负数limit用法分析_php技巧

php中explode的负数limit用法分析_php技巧

WBOY
Release: 2016-05-16 20:22:29
Original
1208 people have browsed it

本文实例讲述了php中explode的负数limit用法。分享给大家供大家参考。具体分析如下:

explode -- 使用一个字符串分割另一个字符串,使之成为数组。
参数为:

array explode ( string separator, string string [, int limit] )
Copy after login

最后的limit可不填,这时将按分割符separator把string全部分光;如果limit填的是正数,则从左至右分割成(limit+1)个个数,如果是负数则从右剔除limit个数组元素(参数为负是从php5.1开始的),留余下部分组成数组。

如:

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

将会看到:

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

可见5、6两个元素删除掉了。

希望本文所述对大家的php程序设计有所帮助。

Related labels:
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