-1

I have this array

array:5 [▼
  0 => "4"
  1 => "5"
  2 => "6"
  3 => "7"
  4 => "8"
]

How do I return the values as 4,5,6,7,8? I have tried encoding into a json string but it returns with unwanted quotes at the beginning and at the end "["4","5","6","7","8"]". I do not want the quotes.

davidkihara
  • 493
  • 1
  • 10
  • 30

1 Answers1

1

You can do it with implode() (example):

$list = implode(',', $array);

Here is the code from the example:

$array = array (0=>"2", 1=>"3", 2=>"4", 3=>"5", 4=>"6");
print_r($array);

$list = implode(',',$array);
echo $list;

Here is the return:

Array
(
    [0] => 2
    [1] => 3
    [2] => 4
    [3] => 5
    [4] => 6
)
2,3,4,5,6
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119