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

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

WBOY
WBOYOriginal
2016-05-16 20:22:291164browse

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

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

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

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

如:

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

将会看到:

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

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

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

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