0

I want to convert

array("r" => "144", "g" => "24", "b" => "26")

to

"144, 24, 26"

I've tried using array_map with strval but it doesn't work.

array_map('strval', $array)

I dont know exactly why it doesn't work.

Diar
  • 123
  • 1
  • 8

1 Answers1

1

You can use implode()

$arr = array("r" => "144", "g" => "24", "b" => "26");
$str = implode(', ',$arr);
// If you want a double quote around string, add following line:
echo '"' . $str . '"';

Working Code:

Pupil
  • 23,834
  • 6
  • 44
  • 66