$colors = ['red', 'green', 'blue'];
$comma_separated = implode(', ', $colors); // 「,」で区切って連結

echo $comma_separated; // 出力: 'red, green, blue'
implode(string $separator, array $array): string
implode(string $separator, array $array);
implode(array $array, string $separator); // 旧方式(現在は非推奨または削除されています)
$fruits = ['apple', 'banana', 'orange'];
$fruits_string = implode(', ', $fruits);

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

echo "HTML List:\n" . $html_list;
結果の出力
class StringArray {
    protected $title;

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

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

$array = [
    new StringArray('春'),
    new StringArray('夏'),
    new StringArray('秋'),
    new StringArray('冬')
];

echo implode('; ', $array); // 出力: '春; 夏; 秋; 冬'
$empty = [];
$result = implode(', ', $empty);

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

echo $query;
// 出力: SELECT * FROM users WHERE id IN (10, 20, 30)
$booleans_array = [true, true, false, false, true];
$result = implode('', $booleans_array);

var_dump($result); // 出力: string(3) '111'
// trueは'1'になり、falseは何も出力されません。