Skip to content
PHP Logo

How can the implode function be used to convert an array to a string in PHP?

The implode function in PHP can be used to convert an array into a string by joining the elements of the array with a specified delimiter. This is useful when you want to display the array elements as a single string. To use the implode function, simply pass the delimiter and the array as arguments, and it will return a string with the array elements concatenated together.

php
// Example array
$array = array('Hello', 'World', 'PHP');

// Convert array to string with comma delimiter
$string = implode(', ', $array);

// Output the result
echo $string; // Output: Hello, World, PHP