0

This Is My Json File Contents and i want to remove parenthesis and brackets and print only numbers:

{"prices":[
[1367107200000,135.3],[1367193600000,141.96],[1367280000000,135.3],[1367366400000,117.0],[1367452800000,103.43],[1367539200000,91.01],[1367625600000,111.25],[1367712000000,116.79],[1367798400000,118.33],[1367884800000,106.4],[1367971200000,112.64],[1368057600000,113.0],[1368144000000,118.78],[1368230400000,113.01],[1368316800000,114.713],[1368403200000,117.18],[1368489600000,114.5],[1368576000000,114.156],[1368662400000,115.5],[1368748800000,123.1],[1368835200000,123.88],[1368921600000,120.501],[1369008000000,122.58],[1369094400000,122.9],[1369180800000,123.0],[1369267200000,125.748],[1369353600000,131.7],[1369440000000,130.77],[1369526400000,134.6],[1369612800000,128.985],[1369699200000,129.179],[1369785600000,132.13]
]}

I do like this :

$str = file_get_contents('Myfile Link Address');
$json = json_decode($str,true);

print_r($json['prices']);

the result is like this :

Array
(
    [0] => Array
        (
            [0] => 1367107200000
            [1] => 135.3
        )

    [1] => Array
        (
            [0] => 1367193600000
            [1] => 141.96
        )

    [2] => Array
        (
            [0] => 1367280000000
            [1] => 135.3
        )
)

I expect the result be like :

[1367107200000,135.3],
[1367193600000,141.96],
[1367280000000,135.3],
[1367366400000,117.0]
...

How Should I Do That?

7
  • print_r($json['prices'][0]); try this Commented Apr 10, 2019 at 8:41
  • you can either loop and print the value after json_decode by adding the brackets by yourself or replace and trim off unnecessary character in front and end of the json string and explode them Commented Apr 10, 2019 at 8:41
  • refer to @ShofiullahBabor you can do this with looping and add the brackets manually Commented Apr 10, 2019 at 8:42
  • foreach($json["prices"] as $key => $value){echo "[".$value[0].",".$value[1]."],";} Commented Apr 10, 2019 at 8:46
  • 1
    @gitguddoge Thanks i see your loop know , thats's correct and workes@ thanks Commented Apr 10, 2019 at 8:49

1 Answer 1

1
foreach($json["prices"] as $key => $value)
{
    echo "[".$value[0].",".$value[1]."],";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.