Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP join() Function

PHP join() Function

PHP String Reference Manual PHP String Reference Manual

Example

Combine array elements into a string:

Run Example »


Definition and Usage

The join() function returns a string formed by joining array elements.

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

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

**Note:** The separator parameter of the join() function is optional. But for backward compatibility, it is recommended to use two parameters.


Syntax

join(

separator,array

)

Parameters Description
separator Optional. Specifies what is placed between array elements. Default is "" (an empty string).
array Required. The array to combine into a string.

Technical Details

Return Value: Returns a string formed by joining array elements.
PHP Version: 4+
Changelog: In PHP 4.3.0,separator parameter became optional.

More examples

Example 1

Separate array elements with different characters:

"; echo join("+",$arr)."
"; echo join("-",$arr)."
"; echo join("X",$arr); ?>

Run Example »


PHP String Reference Manual PHP String Reference Manual