PHP implode () function
Examples
The elements of an array to a string:
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>
Running instance »
Definition and Usage
implode () function returns a combination of array elements into a string.
Note: implode () function accepts two arguments in order.However, due to historical reasons, the explode () is not enough, you must ensure that the separator argument before the string parameter down.
Note: implode () separator function parameters are optional.However, for backward compatibility, it is recommended that you use two parameters.
Note: This function is binary safe.
grammar
implode( separator,array )
参数 | 描述 |
---|---|
separator | 可选。规定数组元素之间放置的内容。默认是 ""(空字符串)。 |
array | 必需。要组合为字符串的数组。 |
technical details
return value: | It returns a combination of array elements into a string. |
---|---|
PHP version: | 4+ |
Update log: | Since PHP 4.3.0, separator parameters become optional. |
More examples
Example 1
An array of characters separated by different elements:
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr)."<br>";
echo implode("+",$arr)."<br>";
echo implode("-",$arr)."<br>";
echo implode("X",$arr);
?>
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr)."<br>";
echo implode("+",$arr)."<br>";
echo implode("-",$arr)."<br>";
echo implode("X",$arr);
?>
Running instance »
PHP String Reference