Home >>PHP String Functions >PHP join() Function
PHP join() function is used to create a string by joining the elements of the given input array. join() function is an in-built function of PHP. PHP join() function works exactly the same as the PHP implode() function. Just like the implode() function in PHP join() function also we pass an array as the input and the function returns an string by joining the elements of the given input array. join() function allows two parameter out of which only one is required & the other one is optional.
Syntax:
join($separator,$array);
Parameter | Description |
---|---|
separator | This is an optional parameter. This parameter specifies what is to be put between the elements of the array. By default it is "" (an empty string). |
array | This is a required parameter. This parameter contains the array which we have to join to a string. |
Here is an example of join() function in PHP:
<html> <body> <?php $a = array('This ','is ','a ','simple ','example ','of ','join() ','function.'); echo join($a); ?> </body> </html>
Here is an another example of join() function in PHP with different separator value:
<html> <body> <?php $a = array('This','is','an','example','of','join()','function','with','seperators'); echo join(" ",$a)."<br>"; echo join("_",$a)."<br>"; echo join("--",$a)."<br>"; echo join("::",$a); ?> </body> </html>