The example in this article describes how PHP uses the explode() function to split a string into an array. Share it with everyone for your reference. The specific analysis is as follows:
explode() function: split the string into an array
The sample code is as follows:
?
1
2
3
4
5
6
|
$str = "朝阳区,海淀区,西城区,东城区,丰台区";
$arr = explode(",",$str);
echo " ";
print_r($arr);
?>
|
1
2
3
4
5
6
1
2
3
4
5
6
7
8
|
Array
(
[0] => 朝阳区
[1] => 海淀区
[2] => 西城区
[3] => 东城区
[4] => 丰台区
)
|
|
$str = "Chaoyang District, Haidian District, Xicheng District, Dongcheng District, Fengtai District";
$arr = explode(",",$str);
echo " ";
print_r($arr);
?>
|
The results are as follows:
?
1
2
3
45
6
7
8
|
Array
(
[0] => Chaoyang District
[1] => Haidian District
[2] => Xicheng District
[3] => Dongcheng District
[4] => Fengtai District
)
|
Supplement:
Syntax: explode(parameter 1, parameter 2)
Parameter 1: What to split by, such as "," in the above example.
Parameter 2: The string that needs to be split.
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/966913.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966913.htmlTechArticlephp uses the explode() function to split a string into an array. This article mainly introduces the use of explode in php The () function is a method of splitting a string into an array, which has certain reference value. It needs...