How to transform array to comma separated words string? [duplicate]

Solution 1:

$arr = array ( 0 => "lorem", 1 => "ipsum", 2 => "dolor");

$str = implode (", ", $arr);

Solution 2:

Directly from the docs:

$comma_separated = implode(",", $array);

Solution 3:

Make your array a variable and use implode.

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);

echo $comma_separated; // lastname,email,phone

http://php.net/manual/en/function.implode.php

Solution 4:

You're looking for implode()

$string = implode(",", $array);