The program output is: Array( [0] => [1] => aa [2] => bb"/> The program output is: Array( [0] => [1] => aa [2] => bb">
Home >Backend Development >PHP Tutorial >explode and implode in php
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>
<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; ?>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>