$colors = ['red', 'green', 'blue'];
$comma_separated = implode(', ', $colors); // Join with a comma delimiter

echo $comma_separated; // Output: 'red, green, blue'
implode(string $separator, array $array): string
implode(string $separator, array $array);
implode(array $array, string $separator); // Legacy syntax (deprecated or removed)
$booleans_array = [true, true, false, false, true];
$result = implode('', $booleans_array);

var_dump($result); // Output: string(3) "111"
// true is converted to "1", and false becomes an empty string.
$fruits = ['apple', 'banana', 'cherry'];
$fruits_string = implode(', ', $fruits);

echo $fruits_string; // Output: 'apple, banana, cherry'
$items = ['Item 1', 'Item 2', 'Item 3'];
$html_list = '<ul><li>' . implode('</li><li>', $items) . '</li></ul>';

echo "HTML List:\n" . $html_list;
Output
class StringArray {
    protected $title;

    public function __construct($title)
    {
        $this->title = $title;
    }

    public function __toString()
    {
        return $this->title;
    }
}

$array = [
    new StringArray('Spring'),
    new StringArray('Summer'),
    new StringArray('Autumn'),
    new StringArray('Winter')
];

echo implode('; ', $array); // Output: 'Spring; Summer; Autumn; Winter'
$empty = [];
$result = implode(', ', $empty);

var_dump($result); // Output: string(0) ""
$ids = [10, 20, 30];
$query = "SELECT * FROM users WHERE id IN (" . implode(', ', $ids) . ")";

echo $query;
// Output: SELECT * FROM users WHERE id IN (10, 20, 30)