Home > Backend Development > PHP Tutorial > How to use the explode() function to split a string into an array in PHP

How to use the explode() function to split a string into an array in PHP

墨辰丷
Release: 2023-03-27 14:06:01
Original
1618 people have browsed it

The function of the explode() function: Use one string to split another string and break it into an array. This article will introduce to you how to use the explode() function in PHP to split a string into an array. Friends who need it can refer to the function of the

explode() function: use one string to split another string and break it up. is an array.

For example:

String

$pizza = "第1 第2 第3 第4 第5 第6";
Copy after login

After splitting according to spaces: $pieces = explode(" " , $pizza);

$pieces is the divided array, let’s print it out and see

";
}
piece1
piece2
piece3
piece4
piece5
piece6
Copy after login

Example 2: According to Comma separated

<?php
$string = &#39;今天太阳很大,我们都没出去。中午我们再食堂吃饭,都很开心!&#39;;
$string_arr = explode(",", $string );
foreach($string_arr as $val){
  echo $val."<br>";
}
Copy after login

Output result:

The sun is very bright today
We didn’t go out. We had a great time eating in the cafeteria at noon!

Related recommendations:

PHP uses preg_split and explode to implement splitting textarea to store content

php explodeFunction introduction and detailed explanation of usage

2017php explodeSummary of function definition and usage

The above is the detailed content of How to use the explode() function to split a string into an array in PHP. For more information, please follow other related articles on the PHP Chinese website!

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