Home  >  Article  >  Backend Development  >  In-depth analysis of PHP connection function implode and split explode_PHP tutorial

In-depth analysis of PHP connection function implode and split explode_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:02:57911browse

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 strings into arrays, and at the same time, it can also connect arrays into strings. To be precise, it can connect array elements into strings. With these two functions, we can combine arrays with Strings can be converted freely. Let’s look at the example in the text below.

implode() connection function:
This function implements concatenating array elements into strings. Before concatenation, 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. I rarely use multi-dimensional arrays, but you can try it.
Example:

Copy code The code is as follows:

$array = array('a' => 1, 'b'=>2, 'c'=>3, 'd'=>4);
$string = implode("-",$array)
echo $string;
//==== The result is: 1-2-3-4;
?>

explode( ) Split function:
This 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 separator exists in the string. We still use the above result as an example
Copy the code The code is as follows:

$string = "1-2-3-4";
$array = explode("-",$string);
echo "< pre>";
print_r($array);
//==== The result is the array defined in the above example, I will not write it out here
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327893.htmlTechArticleThere are many people learning PHP at present. Many friends who are doing PHP training will always ask such a question during their studies. :What is the php connection function implode? PHP can split strings into arrays,...
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