PHP join() Function

Instance

Combine array elements into a string:

<?php
$arr = array('Hello', 'World!', 'I', 'love', 'Shanghai!');
echo join(" ", $arr);
?>

Run Instances

Definition and Usage

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

The join() function is implode() function alias.

Note:The join() function accepts two parameter orders. However, due to historical reasons, explode() is not possible, you must ensure that separator The parameter in string before the parameter.

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

Syntax

join(separator,array)
Parameter Description
separator Optional. Specifies the content placed between array elements. The 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+
Update Log: In PHP 4.3.0,separator The parameter becomes optional.

More Examples

Example 1

Use different characters to separate array elements:

<?php
$arr = array('Hello', 'World!', 'I', 'love', 'Shanghai!');
echo join(" ", $arr) . "<br>";
echo join("+", $arr) . "<br>";
echo join("-", $arr) . "<br>";
echo join("X", $arr);
?>

Run Instances