我使用api
从facebook中删除了这个数组这些是签到列表。
Array
(
[data] => Array
(
[0] => Array
(
[place] => Array
(
[id] => 131703340219561
[name] => Marrakech
[location] => Array
(
[city] => Marrakesh
[country] => Morocco
[latitude] => 31.623668132472
[longitude] => -7.98555101201
[zip] => 40000
)
)
[id] => 10151818357364165
[created_time] => 2013-08-26T18:05:47+0000
)
[1] => Array
(
[place] => Array
(
[id] => 143805719105986
[name] => WESTIVAL Music Festival -31st Jan - 3rd Feb 2013
[location] => Westow House
[start_time] => 2013-01-31T18:00:00+0000
)
[id] => 10151702856746562
[created_time] => 2013-02-03T00:50:39+0000
)
我想搜索数组并检查是否存在['place'] id。
我该怎么做?
答案 0 :(得分:0)
使用foreach循环并检查id是否与您所在的位置匹配。
例如:
foreach($aArray['data'] as $iK=> $aData){
if($iK == 'place'){
//do something
}
foreach($aData[$iK] as $iV =>$aData2){
//do something
}
}
答案 1 :(得分:0)
function hasPlaceId($result, $targetId)
{
if(!array_key_exists('data', $result)
return false;
foreach($result['data'] as $value)
{
if(array_key_exists('place', $value) && array_key_exists('id', $value['place']) && $value['place']['id'] == $targetId)
return true;
}
return false;
}