在php中从json中获取与另一项对应的项


Get item corresponding to another item from json in php

我想用PHP读取这个JSON:

{
["person":{
   {"name":"Bill"},  
   {"age":"56"},
   {"city":"Houston"}
}],
["person":{  
   {"name":"Jack"},
   {"age":"45"},
   {"city":"Dallas"}
}],
["person":{
   {"name":"Henry"},
   {"age":"33"},
   {"city":"Atlanta"}
}]
}

现在我想找那个叫杰克的人,并知道他住在哪个城市。我知道怎么查名字。但是我怎样才能得到相应的城市呢?

我想这样就可以了:

$string = file_get_contents("persons.json");
$json = json_decode($string);
foreach ($json->person as $person) {
   if($person->name == "Jack")
  {
      $city = $person->city;
  }
}