0

我有时将数组作为一个位置或多个位置返回,我想使用变量 $location = egypt 检查数组;如果找到此值,则从所有此位置数组中重新调整此数组

stdClass Object
(
    [count] => 2
    [query] => Cairo
    [locations] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 1190
                    [name] => Cairo, Egypt - 341 hotels
                    [country_name] => Egypt
                    [country_code] => EG
                    [state_name] => 
                    [state_code] => 
                )

            [1] => stdClass Object
                (
                    [id] => 11016
                    [name] => Cairo, GA, United States - 4 hotels
                    [country_name] => United States
                    [country_code] => US
                    [state_name] => {"en":"Georgia"}
                    [state_code] => GA
                )

        )

)
4

1 回答 1

0
function locationReturn($locationArray){
  $result = array();
  foreach($locationArray as $value){
    if($value['country_name'] == 'Egypt')
     return $value;
  }
  return $result; // return empty array if not getting
}
于 2013-09-19T16:15:04.647 回答