Home  >  Article  >  Backend Development  >  Detailed explanation of PHP connection function implode and split explode

Detailed explanation of PHP connection function implode and split explode

怪我咯
怪我咯Original
2017-07-06 11:20:311350browse

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:

The code is as follows:

<?php
    $array = array(&#39;a&#39; => 1, &#39;b&#39;=>2, &#39;c&#39;=>3, &#39;d&#39;=>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!

Statement:
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