The explode() function in
php is: use one string to split another string and return an array composed of strings. The implode() function returns a string composed of array elements. These two functions are
mutual conversion functions between strings and arrays.
First of all, from the usage point of view, one is to connect array elements into strings, and the other is to split strings into arrays. So the usage is different.
Then there are differences in the parameters received. Due to historical reasons, explode() cannot accept two parameter orders. It must ensure that the separator parameter comes before the string parameter;
And implode() can accept two parameter orders.
Example
implode() connection function:
<?php $array = array('a' => 1, 'b'=>2, 'c'=>3, 'd'=>4); $string = implode("-",$array); echo $string; ?>
with running results As shown below:
##explode() split function:
Note that this separator exists in the string, we still Use the above results as an example<?php $string = "1-2-3-4"; $array = explode("-",$string); echo "<pre class="brush:php;toolbar:false">"; print_r($array); ?>
The explode() method is often used to enter multiple options, separate them with specific delimiters, and convert them into an array.
implode() converts the array into a string. When constructing the sql statement, for example
insert into table (col1,col2,col3) values('value1','value2','value3')
, this construction can become simpler
【Recommended related articles】
1.
Detailed explanation of php explode() function exampleDetailed explanation of php implode() function exampleThe above is the detailed content of The difference in usage between php implode() function and explode() function. For more information, please follow other related articles on the PHP Chinese website!