Home  >  Article  >  Backend Development  >  Detailed explanation of php implode() function example

Detailed explanation of php implode() function example

怪我咯
怪我咯Original
2017-05-23 14:53:393804browse

What is the function of php implode() function?

The implode() function in php returns a string composed of array elements. It has the opposite effect to the php explode() function. php explode() The function is: split a string using another string and return an array of strings.

Understanding the role of the php implode() function, let’s take a look at the syntax and examples of the php implode() function

Grammar

implode(separator,array)

Parameter details:

##ParameterDescriptionOptional. Specifies what is placed between array elements. Default is "" (empty string). Required. Arrays to be combined into strings.
separator
array

Note: The implode() function accepts two parameter orders. However, due to historical reasons, explode() does not work. You must ensure that the separator parameter comes before the string parameter.

Note: The separator parameter of the implode() function is optional. However, for backward compatibility, it is recommended that you use two parameters.

Example

Use different characters to separate array elements, the code is as follows:

<?php
$arr = array(&#39;Hello&#39;,&#39;World!&#39;,&#39;Beautiful&#39;,&#39;Day!&#39;);
echo implode(" ",$arr)."<br>";

echo implode("+",$arr)."<br>";

echo implode("-",$arr)."<br>";

echo implode("X",$arr);
?>

Code running result:

Detailed explanation of php implode() function example

【Recommended related articles】

1.

php explode() function example detailed explanation

2.

Use of php explode() function method

The above is the detailed content of Detailed explanation of php implode() function example. 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