How to create a string by joining the values of an array in PHP

The  implode() or join() is a built-in function in PHP and it is used for creating a string by joining the elements or values of an array with a glue string like hyphen (-) or comma (,).



separator – This parameter is Optional. It Specifies what to put between the array values or elements. Default is “” (an empty string).

array – This parameter is required. The array to join to a string.


$array = array("HTML", "CSS", "PHP");

// Turning array into a string
$str = implode(", ", $array);
echo $str; // Outputs: HTML, CSS, PHP
echo '<br>';
$str = implode(" - ", $array);
echo $str; // Outputs: HTML - CSS - PHP

Praveen Kumar

I am a fullstack web developer with a passion for SEO, creating stunning websites, and organic marketing. I am a perfectionist.

Post navigation