Home > Backend Development > PHP Tutorial > explode and implode in php

explode and implode in php

PHP中文网
Release: 2023-02-28 21:48:02
Original
2297 people have browsed it

The function of explode is to use one string to split another string. Returns a split array.

Let’s look at the basic usage of explode:

<br>
Copy after login

<br>The program output is:

Array<br>(<br> [0] => <br> [1] => aa<br> [2] => bb<br> [3] = > <br>)<br>

You can see that the first and last x of the string str are interpreted as spaces, and the middle x splits the string in half. If there are multiple x's in the middle, the extra x's will be interpreted as spaces.

If str is set to xaaxxxbbx

, the output of the program is:

Array<br>(<br> [0] => <br> [1] => aa<br> [2] => <br> [4] => bb<br> [5] => <br>)<br><br>

explode also has an optional parameter limit.

The function of limplode is to convert a one-dimensional array into a string. Let’s look at its basic usage:

 'aa',
    'b' => 'bb',
    'c' => 'cc'
);
$str  = implode('x', $data);
echo $str;
?>
Copy after login
The program output is: aaxbbxcc

The first parameter is the connector, if it is a space, The output is aa bb cc. If the first parameter is not filled in, the output is aabbcc

<br>

The above introduces explode and implode in PHP. I hope it will be helpful to friends who are interested in PHP tutorials.

<br>

Related labels:
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
Latest Articles by Author
Latest Issues
explode function splits an array
From 1970-01-01 08:00:00
0
0
0
Explode array based on value
From 1970-01-01 08:00:00
0
0
0
Resize image before upload in Laravel 5.8
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template