Amin Arjmand
Amin Arjmand

Reputation: 455

How Can I Read Data From Json File In Custom Type In PHP Laravel?

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?

Upvotes: 0

Views: 75

Answers (1)

gitguddoge
gitguddoge

Reputation: 172

foreach($json["prices"] as $key => $value)
{
    echo "[".$value[0].",".$value[1]."],";
}

Upvotes: 1

Related Questions