Home > Article > Backend Development > Detailed explanation of PHP connection function implode and split explode
This article is a detailed analysis and introduction of php connection function implode and segmentation explode. Friends who need it can refer to it
There are many people learning PHP at present. Many friends who are doing PHP training will always ask this question during their studies: What is the PHP connection function implode?
php can split string into arrays, and at the same time, you can also connect arrays into strings. To be precise, you can connect array elements into strings. With these two functions We can freely convert between arrays and strings. Let’s look at the example in the text.
implode() connection function:
This function implements connecting array elements into strings. Before connecting, we need to give it two parameters, one is The connector one is the array to be connected
Note that it is a one-dimensional array Oh, multi-dimensional editor rarely uses it, but you can try it.
Example:
<?php $array = array('a' => 1, 'b'=>2, 'c'=>3, 'd'=>4); $string = implode("-",$array) echo $string; //==== 结果就是:1-2-3-4; ?>
##explode() Split function:
This function The function is to split the string into an array. We still give it two parameters, one is the delimiter and the other is the string to be split Note that this delimiter exists in the string, we Still using the above results as an example
The code is as follows:
<?php $string = "1-2-3-4"; $array = explode("-",$string); echo "<pre class="brush:php;toolbar:false">"; print_r($array); //==== 结果就是上面例子定义的数组喽,这里小编就不写出来了 ?>
The above is the detailed content of Detailed explanation of PHP connection function implode and split explode. For more information, please follow other related articles on the PHP Chinese website!