1

What will be the fastest and best way to convert the following PHP associate array to a string without json.

array

 Array ( [0] => A [1] => S [2] => G) 

to a string, exactly like

String =  "A, S, G";

Most of the solutions available are using JSON, that I don't want to use. plus I want to know the "Fastest" and "Best" way.

qammar
  • 79
  • 2
  • 10
  • @Rizier123 Most of those solutions are json, that I can't use. plus, I want to know the 'Fastest' and best way. – qammar Jan 25 '17 at 18:47
  • 1
    Why not consider the accepted answer to that duplicate question? What makes you believe that it isn't the fastest and best way? – Mark Baker Jan 25 '17 at 19:46

3 Answers3

3

Use the implode function:

$str = implode(array('a', 'b', 'c'));

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

Chip Dean
  • 4,222
  • 3
  • 24
  • 36
0

Use implode()

And read more here http://php.net/manual/en/function.implode.php

sztyvny
  • 17
  • 3
-1

One way is using print_r(array, true) and it will return string representation of array

halfer
  • 19,824
  • 17
  • 99
  • 186
Hiren Jungi
  • 854
  • 8
  • 20