Home > php教程 > php手册 > body text

php中explode的负数limit用法分析

WBOY
Release: 2016-06-06 20:08:40
Original
1270 people have browsed it

这篇文章主要介绍了php中explode的负数limit用法,实例分析explode中limit参数为负的用法,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了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程序设计有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!