PHP join() Function

PHP htmlentities() Function
PHP implode() Function

In this article, you will learn about how to convert the array into a string in PHP. The join() function converts the array into a string or in other words, it returns a string by joining the elements of the array.

Join() function is an alias of the implode() function. Also, it accepts the parameters in both lefts to right/right to left order. However, they are passed in the order of convention (like explode() function).

You can also specify the separator character but it is not mandatory. However, for backward compatibility, you must use the two arguments.

WHat is the syntax of the join() function in Php?

join(separator,array)
ParametersDetails
separatorIt specifies the character or string to place between two array elements while joining them – Optional
arrayThe array to consider to convert to string
PHP join() method

examples of the join() function

Example 1. In this example, we take an array with some string elements in it. We created a string by joining all the strings of the array.

<?php
$arr = array('Hello','PHP!','Sunny','Weather!');
echo join(" ",$arr);
?>

Example 2. In this example, we join the array by using different separator characters.

<?php
$arr = array('Hello','PHP!','Sunny','Day!');
echo join(/ ",$arr)."<br>";
echo join("AB",$arr)."<br>";
echo join("-",$arr)."<br>";
echo join("_",$arr);
?>
PHP htmlentities() Function
PHP implode() Function
en English
X
Scroll to Top