PHP join()Functions

PHP String 参考手册PHP String Reference Manual

Examples

Combine array elements into a string:

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

Run example »

Definition and Usage

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

The join() function isimplode()an alias of the function.

Note:The join() function accepts two parameter orders. However, for historical reasons,explode()is not acceptable; you must ensure that the separator parameter comes before the string parameter.

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


Syntax

join(separator,array)

Parameters Description
separator Optional. Specifies what is placed between 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 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 join(" ",$arr)."<br>";
echo join("+",$arr)."<br>";
echo join("-",$arr)."<br>";
echo join("X",$arr);
?>

Run example »


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