PHP join() Functions

Example

Combine array elements into a string:

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

Run Instance

Definition and Usage

join() Functions return a string composed of array elements.

join() Functions are implode() function alias.

Note:join() Functions accept two parameter orders. However, due to historical reasons, explode() is not allowed, you must ensure that separator Parameter in string before the parameter.

Note:join() Functions 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