PHP implode()Functions

PHP String 参考手册PHP String Reference Manual

Examples

Combine array elements into a string:

<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>

Run Example »

Definition and Usage

The implode() function returns a string composed of array elements.

Note:The implode() function accepts two argument orders. However, for historical reasons,explode()it is not allowed; 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.

Note:This function is binary-safe.


Syntax

implode(separator,array)

Parameter Description
separator Optional. Specifies what is placed between the array elements. Default is "" (empty string).
array Required. The array to be combined into a string.

Technical Details

Return Value: Returns a string composed of the array elements.
PHP Version: 4+
Changelog: In PHP 4.3.0,separatorthe parameter became optional.


More Examples

Example 1

Separate array elements with different characters:

<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr)."<br>";
echo implode("+",$arr)."<br>";
echo implode("-",$arr)."<br>";
echo implode("X",$arr);
?>

Run Example »


PHP String 参考手册PHP String Reference Manual Other Extensions