-6

how can I parse this string into an array using php?.

[[1406906881,9.3],[1406907001,9.5],[1406907061,9.5],[1406907121,9.8],[1406907181,9.4],[1406907241,9.6],[1406907361,9.3],[1406907421,9.3],[1406907481,9.1],[1406907541,9.2],[1406907601,9],[1406907661,9],[1406907781,8.9],[1406907841,9],]
3
  • Where is it coming from? Narnia? Commented Aug 8, 2014 at 14:50
  • did you give it a try?? Commented Aug 8, 2014 at 14:52
  • what is the normal way? the commas are a problem Commented Aug 8, 2014 at 14:54

2 Answers 2

0

Looks like you have a trailing comma

[1406907661,9],[1406907781,8.9],[1406907841,9],]
                                              ^

Not sure if that's what you're asking about.

Sign up to request clarification or add additional context in comments.

Comments

0

You can parse this using json_decode() function in PHP. That string looks like json array.

Also, fix that trailing comma in the string (as mentioned by Alf).

Working example:

<pre>
<?php

$jsonArr = json_decode('[[1406906881,9.3],[1406907001,9.5],[1406907061,9.5],[1406907121,9.8],[1406907181,9.4],[1406907241,9.6],[1406907361,9.3],[1406907421,9.3],[1406907481,9.1],[1406907541,9.2],[1406907601,9],[1406907661,9],[1406907781,8.9],[1406907841,9]]');

print_r($jsonArr);

?>

Outputs:

enter image description here

2 Comments

It doesn't work, the json_decode doen't decode the string
did you fix the trailing comma as mentioned by Alf - see post below

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.