Home >>PHP Tutorial >PHP join() Function

PHP join() Function

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 Values

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>
Output:
This is a simple example of join() function.

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>
Output:
This is an example of join() function with seperators
This_is_an_example_of_join()_function_with_seperators
This--is--an--example--of--join()--function--with—seperators
This::is::an::example::of::join()::function::with::seperators

Popular Tutorials