PHP join() Function

Example

Combine array elements into a string:

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

Run Instance

Definition and Usage

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

join() function is implode() function alias.

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

Note: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 Parameters become optional.

More Examples

Example 1

Separate array elements with different characters:

<?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 Instance