1

I'm wondering how do i access the 3rd "value" using PHP in the following:

   "data": [
      {
         "id": "-",
         "name": "-",
         "period": "-",
         "values": [
            {
               "value": 0,
               "end_time": "2011-10-08T07:00:00+0000"
            },
            {
               "value": 0,
               "end_time": "2011-10-09T07:00:00+0000"
            },
            {
               "value": 0,
               "end_time": "2011-10-10T07:00:00+0000"
            }
         ]

As for now I'm trying to do something with:

$results = json_decode(curl_exec ($curl));

But then I'm stuck because there are 3 "value" inside of "values" and to tell you the truth I'm pretty confused..

Ricardo
  • 1,653
  • 8
  • 26
  • 51

1 Answers1

0

this code is just for your understanding you can get the better idea from this.

<?php

$json = '[{"id": "-","name": "-","period": "-","values": [{"value": 0,"end_time": "2011-10-08T07:00:00+0000"},{"value": 0,"end_time": "2011-10-09T07:00:00+0000"},{"value": 0,"end_time": "2011-10-10T07:00:00+0000"}]}]';

$jasondata =json_decode($json,true);

echo $jasondata[0]['values'][2]['value']; exit;

echo "<pre>"; print_r($jasondata); exit;
?>
Brendan Bullen
  • 11,607
  • 1
  • 31
  • 40
Praveen kalal
  • 2,148
  • 4
  • 19
  • 33