The join() function, an alias of the implode() function, returns a string from the elements of an array.
PHP join() Function has the following syntax.
join(separator,array)
Parameter | Is Required | Description |
---|---|---|
separator | Optional. | What to put between the array elements. Default is "" (an empty string) |
array | Required. | The array to join to a string |
PHP join() Function returns a string from elements of an array.
Join array elements with a string:
<?php
$arr = array('Hello','World!','from','java2s.com!');
echo join(" ",$arr);
?>
The code above generates the following result.
Separate the array elements with different characters:
<?php
$arr = array('Hello','World!','from','java2s.com!');
echo join(" ",$arr)."\n";
echo join("+",$arr)."\n";
echo join("-",$arr)."\n";
echo join("X",$arr);
?>
The code above generates the following result.