csmit195

Brandon Smith - JSON Decoding

Mar 21st, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | None | 0 0
  1. <?php
  2. // Replace people.json with your JSON File
  3. $jsonstr = file_get_contents("people.json");
  4. $jsonArray = json_decode($jsonstr, true);
  5.  
  6. foreach($jsonArray as $record){
  7.     $name = $record['name'];
  8.     $address = $record['address'];
  9.     $phone = $record['phone'];
  10.    
  11.     // Checking if query is the same.
  12.     if ($query['name'] === $name && $query['address'] === $address){
  13.         echo $phone;
  14.         break;
  15.     }
  16. }
  17. ?>
Advertisement
Add Comment
Please, Sign In to add comment