fork download
  1. <?php
  2. $jsondata = '{"contacts":[
  3. {"id":1,"address":"address1","tel":"40071322","doctor_id":1,"type_id":1,"lng":"51.374720","lat":"35.781986","city_id":186,"province_id":8,"hour_about":null,"place_name":null},
  4. {"id":2,"address":"address2","tel":null,"doctor_id":1,"type_id":2,"lng":"51.520313","lat":"35.726983","city_id":186,"province_id":8,"hour_about":null,"place_name":null},
  5. {"id":3,"address":"address3","tel":null,"doctor_id":1,"type_id":2,"lng":"51.456368","lat":"35.797505","city_id":186,"province_id":8,"hour_about":null,"place_name":null}
  6. ]}';
  7. $jsonArray = json_decode($jsondata, true);
  8.  
  9. print_r ($jsonArray);
  10.  
  11.  
  12. foreach($jsonArray["contacts"] as $person) {
  13. if($person['city_id'] == 186) {
  14. echo "id = " . $person['id'] . ", ";
  15. }
  16. }
  17. ?>
  18.  
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Array
(
    [contacts] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [address] => address1
                    [tel] => 40071322
                    [doctor_id] => 1
                    [type_id] => 1
                    [lng] => 51.374720
                    [lat] => 35.781986
                    [city_id] => 186
                    [province_id] => 8
                    [hour_about] => 
                    [place_name] => 
                )

            [1] => Array
                (
                    [id] => 2
                    [address] => address2
                    [tel] => 
                    [doctor_id] => 1
                    [type_id] => 2
                    [lng] => 51.520313
                    [lat] => 35.726983
                    [city_id] => 186
                    [province_id] => 8
                    [hour_about] => 
                    [place_name] => 
                )

            [2] => Array
                (
                    [id] => 3
                    [address] => address3
                    [tel] => 
                    [doctor_id] => 1
                    [type_id] => 2
                    [lng] => 51.456368
                    [lat] => 35.797505
                    [city_id] => 186
                    [province_id] => 8
                    [hour_about] => 
                    [place_name] => 
                )

        )

)
id = 1, id = 2, id = 3,