[ create a new paste ] login | about

Link: http://codepad.org/nZqAsofx    [ raw code | output | fork ]

PHP, pasted on May 22:
<?php

$json = '{
   "valid":true,
   "id":"0",
   "data":{
      "@type":"genericObjectArray",
      "item":[
         {
            "id":"DE",
            "description":"Deutschland"
         },
         {
            "id":"ES",
            "description":"España"
         },
         {
            "id":"FR",
            "description":"France"
         },
         {
            "id":"PT",
            "description":"Portugal"
         },
         {
            "id":"UK",
            "description":"United Kingdom"
         },
         {
            "id":"US",
            "description":"United States"
         }
      ]
   }
}';

$data = json_decode($json, TRUE);

var_dump($data);


$countries = array(); 

foreach($data['data']['item'] as $item) {
    $countries[] = $item['description'];
}

var_dump($countries);


Output:
array(3) {
  ["valid"]=>
  bool(true)
  ["id"]=>
  string(1) "0"
  ["data"]=>
  array(2) {
    ["@type"]=>
    string(18) "genericObjectArray"
    ["item"]=>
    array(6) {
      [0]=>
      array(2) {
        ["id"]=>
        string(2) "DE"
        ["description"]=>
        string(11) "Deutschland"
      }
      [1]=>
      array(2) {
        ["id"]=>
        string(2) "ES"
        ["description"]=>
        string(9) "España"
      }
      [2]=>
      array(2) {
        ["id"]=>
        string(2) "FR"
        ["description"]=>
        string(6) "France"
      }
      [3]=>
      array(2) {
        ["id"]=>
        string(2) "PT"
        ["description"]=>
        string(8) "Portugal"
      }
      [4]=>
      array(2) {
        ["id"]=>
        string(2) "UK"
        ["description"]=>
        string(14) "United Kingdom"
      }
      [5]=>
      array(2) {
        ["id"]=>
        string(2) "US"
        ["description"]=>
        string(13) "United States"
      }
    }
  }
}
array(6) {
  [0]=>
  string(11) "Deutschland"
  [1]=>
  string(9) "España"
  [2]=>
  string(6) "France"
  [3]=>
  string(8) "Portugal"
  [4]=>
  string(14) "United Kingdom"
  [5]=>
  string(13) "United States"
}


Create a new paste based on this one


Comments: