Home  >  Article  >  Backend Development  >  How to use php implode function

How to use php implode function

藏色散人
藏色散人Original
2019-02-01 10:24:186497browse

PHP implode function is used to convert the value of a one-dimensional array into a string. Its syntax is implode(separator,array). The parameter array is required and refers to the array to be combined into a string.

How to use php implode function

#How to use the php implode function?

php implode() function syntax

Function: combine array elements into strings

Syntax:

implode(separator,array)

Parameters:

separator Optional. Specifies what is placed between array elements. Default is "" (empty string).

array Required. Arrays to be combined into strings.

Note:

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

php implode() function usage example 1:

<?php
$arr = array(&#39;Hello&#39;,&#39;World!&#39;,&#39;I&#39;,&#39;love&#39;,&#39;PHP!&#39;);
echo implode(" ",$arr);
?>

Output:

Hello World! I love PHP!

php implode() function usage example 2:

<?php
$arr = array(&#39;Hello&#39;,&#39;World&#39;,&#39;I&#39;,&#39;love&#39;,&#39;PHP&#39;);
echo implode("!",$arr);
?>

Output:

Hello!World!I!love!PHP

This article is an introduction to the PHP implode function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php implode function. 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