以下函數將檢索主要在大學中給定主題的活動用戶的朋友列表。數據是從Facebook GRAPH API中提取的。 (此功能)...在數組的多維數組中查找值
function getCollegeFriends() {
$config = array(
'appId' => 'XXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXX',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
try {
$fql = "select uid,name,education from user WHERE uid IN (select uid2 from friend where uid1=($user_id))";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
}
catch(Exception $o){
d($o);
}
$friends = $fqlResult;
$friends_BA = array();
foreach ($friends as $friend) {
$isBA = false;
if (is_array($friend['education'])) {
foreach ($friend['education'] as $school) {
if (isset($school)) {
foreach ($school['school'] as $name) {
$lowerName = strtolower($name);
if (strpos($lowerName, 'university of central florida') !== false || strpos($lowerName, 'ucf') !== false) {
$friends_BA[] = $friend['name'];
continue 3; // skip to the next friend
}
}
}
}
}
}
echo '<pre>';
print_r($friends_BA);
echo '</pre>';
}
現在我工作的一個函數返回的誰在同一家公司工作的朋友列表,持有相同的工作崗位等。以下是我的失敗刺傷功能:
function getWorkerFriends() {
$config = array(
'appId' => 'XXXXXXXXX',
'secret' => 'XXXXXXXXX',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
try {
$fql = "select uid,name,work_history from user WHERE uid IN (select uid2 from friend where uid1=($user_id))";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
}
catch(Exception $o){
d($o);
}
$friends = $fqlResult;
$friends_BA = array();
foreach ($friends as $friend) {
$isBA = false;
if (is_array($friend['work_history'])) {
foreach ($friend['work_history'] as $employer) {
if (isset($employer)) {
foreach ($employer['location'] as $name) {
$lowerName = strtolower($name['company_name']);
if (strpos($lowerName, 'ubs') !== false || strpos($lowerName, 'merion') !== false) {
$friends_BA[] = $friend['name'];
continue 3; // skip to the next friend
}
}
}
}
}
}
echo '<pre>';
print_r($friends_BA);
echo '</pre>';
}
該解決方案只是返回一個空數組,但測試用戶確實有滿足函數要求的朋友。以下是用戶朋友列表的數組。我們將不勝感激任何有關建議解決方案的幫助。我在第三天現在這個問題的:
(注:每個[OFFSET]是一個不同的朋友活躍用戶:
[124] => Array
(
[uid] => 553325624
[name] => Persons Name
[current_location] => Array
(
[city] => Los Angeles
[state] => California
[country] => United States
[zip] =>
[id] => 110970792260960
[name] => Los Angeles, California
)
[work_history] => Array
(
)
[education] => Array
(
[0] => Array
(
[school] => Array
(
[id] => 111894272160018
[name] => Spanish River Community High School
)
[type] => High School
)
[1] => Array
(
[school] => Array
(
[id] => 110186095670702
[name] => North Broward Preparatory Schools
)
[type] => High School
)
)
)
[125] => Array
(
[uid] => 560613217
[name] => Persons Name
[current_location] => Array
(
[city] => Summit
[state] => New Jersey
[country] => United States
[zip] =>
[id] => 103727996333163
[name] => Summit, New Jersey
)
[work_history] => Array
(
[0] => Array
(
[location] => Array
(
[city] =>
[state] =>
)
[company_name] => Camp High Rocks
[description] =>
[start_date] =>
[end_date] =>
)
)
[education] => Array
(
[0] => Array
(
[school] => Array
(
[id] => 106165586082302
[name] => Summit Senior High School
)
[type] => High School
)
[1] => Array
(
[school] => Array
(
[id] => 6192688417
[name] => Stanford University
)
[year] => Array
(
[id] => 105576766163075
[name] => 2015
)
[type] => College
)
)
)
開始的var_dump「荷蘭國際集團各的foreach()之前,它應該會顯示您的腳本失敗。 – Erik 2012-01-15 00:20:08
你究竟在哪裏指什麼?以及哪些變量BLES?我嘗試了一些,但得到了空陣列。 – buttonitup 2012-01-15 02:00:46
錯誤將發生在確實有數據的最後一個數組和第一個沒有數據的數組之間。 – Erik 2012-01-15 02:21:32