Combine array elements into a string:
<?php$arr = array('Hello','World!','Beautiful','Day!');echo implode(" ",$arr);?>The implode() function returns a string composed of array elements.
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.
Note: This function is binary safe.
implode( separator,array )
parameter | describe |
---|---|
separator | Optional. Specifies what is placed between array elements. Default is "" (empty string). |
array | Required. Arrays to be combined into strings. |
Return value: | Returns a string composed of array elements. |
---|---|
PHP version: | 4+ |
Update log: | In PHP 4.3.0, the separator parameter became optional. |
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);?>