-1

So, I have some JSON data that looks like this:

  {  
   "Table1":[  
      {  
         "CURRENCY_FLAG":"EUR",
         "TRADE_DATE":"2015-10-15",
         "DELIVERY_DATE":"2015-10-15",
         "DELIVERY_HOUR":"7",
         "DELIVERY_INTERVAL":"1",
         "RUN_TYPE":"EA",
         "SMP":"35.370",
         "LAMBDA":"35.370",
         "SYSTEM_LOAD":"3164.611",
         "CMS_TIME_STAMP":"2015-10-14T10:03:09+01:00"
      },
      {  
         "CURRENCY_FLAG":"GBP",
         "TRADE_DATE":"2015-10-15",
         "DELIVERY_DATE":"2015-10-15",
         "DELIVERY_HOUR":"7",
         "DELIVERY_INTERVAL":"1",
         "RUN_TYPE":"EA",
         "SMP":"26.460",
         "LAMBDA":"26.460",
         "SYSTEM_LOAD":"3164.611",
         "CMS_TIME_STAMP":"2015-10-14T10:03:09+01:00"
      }... etc

I'm pretty basic at PHP, but have fetched this data with CURL, and now I want to iterate through this data and remove every node with the "GBP" value for "CURRENCY_FLAG" and just hang onto those with the "EUR" sign.

Can anyone point me in the right direction of parsing this with PHP?

Thanks!

iAsk
  • 57
  • 1
  • 9
  • 4
    [`json_decode()`](http://php.net/manual/en/function.json-decode.php) does the parsing for you. The rest is just plain manipulation of PHP data structures. – axiac Feb 02 '16 at 16:26
  • read the answer [http://stackoverflow.com/questions/4343596/parsing-json-file-with-php] to see the process of iterating over an array. I'm flagging this as a duplicate – OYRM Feb 02 '16 at 16:43

1 Answers1

0

Try simply this way after decoding your json string using json_decode()

//decode json string
$result = json_decode($curl_result, true);

 $final_result = [];
 foreach($result['Table1'] as $key => $value){
    if($value['CURRENCY_FLAG'] != 'GBP'){  //exclude currency flag with GBP
      $final_result[] = $value;
    }
 }

print '<pre>';
print_r($final_result);
print '</pre>';
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
  • I'm so useless with PHP. To drill down to a lower level once those items have been found and stored in the array, how would I go about only storing the following items only, and forgetting the rest. "CURRENCY_FLAG":"GBP", "DELIVERY_DATE":"2015-10-15", "DELIVERY_HOUR":"7", "DELIVERY_INTERVAL":"1", "SMP":"26.460", – iAsk Feb 02 '16 at 20:13