PHP join() Function


The join() function returns a string consisting of the elements of the array. The "join()" function is an alias for the "implode()" function. This function accepts parameters in any order. However, for consistency with explosion(), you must use the documented argument order. The separator parameter for join() is optional. However, it is recommended to always use two parameters for backwards compatibility.

Syntax
join(separator,array)
Parameters
  • separator - (Optional) Specifies what to insert between array elements. The default value is "" (empty string).
  • array - (Required) Array to concatenate with string.
Example
<?php
$str = array('Hi','Hello','Welcome','World');
echo join(" ",$str);
?>

Output

Hi Hello Welcome World

Concatenate array elements with string

Example
<?php
$str = array('Hi','Hello','Welcome','World');
            
//join(" ", $str) will join the elements with a Space as the separator.
echo join(" ", $str)."<br>";
            
//join("+", $str) will join the elements with a Plus sign as the separator. 
echo join("+", $str)."<br>";
            
//join("-", $str) will join the elements with a Hyphen as the separator.
echo join("-", $str)."<br>";
            
//join("*", $str) will join the elements with the letter '*' as the separator.
echo join("*", $str);
?>

Output

Hi Hello Welcome World
Hi+Hello+Welcome+World
Hi-Hello-Welcome-World
Hi*Hello*Welcome*World

Prev Next