-3

I have array like this

$test=Array ( [0] => en [1] => fr )

when I use this command

$a=implode(",",$test);
print_r($a);

result is:

en,fr

but I want this result

'en','fr'

paranoid
  • 6,799
  • 19
  • 49
  • 86

2 Answers2

6

change like this

$a="'".implode("','",$test)."'";

Check your output : https://eval.in/587278

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
2

This could be an option:

$a = implode(",", array_map(function($el) {return "'" . $el . "'";}, $test));

This approach focuses on readability and generality. You could have another transformation for each array element, using an anonymous function, before imploding.

xnakos
  • 9,870
  • 6
  • 27
  • 33