Home > Backend Development > PHP Tutorial > php使用explode()函数将字符串拆分成数组的方法_php技巧

php使用explode()函数将字符串拆分成数组的方法_php技巧

WBOY
Release: 2016-05-16 20:23:01
Original
1924 people have browsed it

本文实例讲述了php使用explode()函数将字符串拆分成数组的方法。分享给大家供大家参考。具体分析如下:

explode()函数:字符串拆分成数组

示例代码如下:

<&#63;php
$str = "朝阳区,海淀区,西城区,东城区,丰台区";
$arr = explode(",",$str);
echo "<pre class="brush:php;toolbar:false">";
print_r($arr);
&#63;>
Copy after login

结果如下:

<pre class="brush:php;toolbar:false">Array
(
  [0] => 朝阳区
  [1] => 海淀区
  [2] => 西城区
  [3] => 东城区
  [4] => 丰台区
)
Copy after login

补充:

语法:explode(参数1,参数2)
参数1:按什么来拆分,如上例中的","。
参数2:需要拆分的字符串。

希望本文所述对大家的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