-5

I have this string array:

["652","110","111","1032","118","416","147","121","112","1033","113","1031","868"]

I need to read each value so to get

652
110
111
1032

i try to convert string array using explode and then foreach but is not working...

$channels = explode('"', $string_array);

foreach($channels as &$channel) {
    echo $channel.'<br>';
}
6
  • 2
    Is it an array or string ? Commented Dec 4, 2017 at 20:17
  • 3
    This is a JSON string, use json_decode(). Commented Dec 4, 2017 at 20:22
  • It doesn't look like a JSON string to me, it looks like a php array literal. Commented Dec 4, 2017 at 20:32
  • How is this json string generated / where does it come from? stackoverflow.com/questions/25568420/… Commented Dec 4, 2017 at 20:50
  • Related: stackoverflow.com/a/21369519/2943403 Commented Dec 4, 2017 at 23:12

1 Answer 1

3

it's an JSON format, so use json_decode

$json = '["652","110","111","1032","118","416","147","121","112","1033","113","1031","868"]';
$array = json_decode($json, true);
foreach($array AS $channel) {
    echo $channel.'<br>';
}
Sign up to request clarification or add additional context in comments.

9 Comments

It gives an error
what the error you got?
missing your single quotes, to make it not a PHP array ;p
json_decode() expects parameter 1 to be string, array given
yes... put all the json string in single quotes ... i updated the code
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.