-4

i have a array and how can i cover it to string fastest ?

Array
(
    [1] => 1,
    [2] => 8,
    [3] => 10,
    [4] => 16,
)

I need cover it to this string $var = (1,8,10,16)

Phuc Vo
  • 235
  • 5
  • 17
  • 1
    Do you mean "convert"? – Don't Panic Oct 11 '16 at 14:00
  • 2
    Possible duplicate of [Convert array to string](http://stackoverflow.com/questions/5237211/convert-array-to-string) – Don't Panic Oct 11 '16 at 14:02
  • Possible duplicate of [Array to String PHP?](http://stackoverflow.com/questions/7490488/array-to-string-php) – Dave Oct 11 '16 at 14:03
  • Also [this](http://stackoverflow.com/questions/4626732/merge-array-items-into-string) and [this](http://stackoverflow.com/questions/6007598/convert-array-into-string-in-php?noredirect=1&lq=1). – Don't Panic Oct 11 '16 at 14:03

2 Answers2

0

Just implode it:

$var = '(' . implode(',', $data) . ');

Live example: https://3v4l.org/9bsZF

danopz
  • 3,310
  • 5
  • 31
  • 42
0

you can use simple implode function for that .

    $arr = array(
        "1" => 1,
        "2" => 8,
        "3" => 10,
        "4" => 16
        );
echo implode($arr, ",");

output : 1,8,10,16

OR

foreach ($arr as $value) {
     echo $value .", ";
 }

Output : 1, 8, 10, 16,

Ankneema
  • 45
  • 5