Php 如何获取facebook用户的工作和教育信息,并将其存储到变量或数组中
我在存储Facebook用户的工作和教育信息方面面临问题 以下是我获取用户信息的方式:Php 如何获取facebook用户的工作和教育信息,并将其存储到变量或数组中,php,facebook-graph-api,multidimensional-array,associative-array,Php,Facebook Graph Api,Multidimensional Array,Associative Array,我在存储Facebook用户的工作和教育信息方面面临问题 以下是我获取用户信息的方式: $profile_request=$fb->get('/me?fields=name,first_name,last_name,email,work,education'); 然后将响应转换为多维数组: $profile = $profile_request->getGraphNode()->asArray(); 这就是我得到答复的方式: $profile=Array (
$profile_request=$fb->get('/me?fields=name,first_name,last_name,email,work,education');
然后将响应转换为多维数组:
$profile = $profile_request->getGraphNode()->asArray();
这就是我得到答复的方式:
$profile=Array
(
"name" => "abc pqr",
"first_name" => "abc",
"last_name" => "pqr",
"email" => "abc@gmail.com",
"work" => Array
(
"0" => Array
(
"employer" => Array
(
"id" => "348468651959125",
"name" => "Karachi university"
),
"location" => Array
(
"id" => "110713778953693",
"name" => "Karachi, Pakistan"
),
"position" => Array
(
"id" => "1556082398000870",
"name" => "Lecturer"
),
"start_date" => "2008-04-25"
),
"1" => Array
(
"description" => "i am teaching......",
"end_date" => "2011-06-20",
"employer" => Array
(
"id" => "486743441453589",
"name" => "Happy Palace Grammar School NORTH 3 - J2"
),
"location" => Array
(
"id" => "110713778953693",
"name" => "Karachi, Pakistan"
),
"position" => Array
(
"id" => "1556082398000870",
"name" => "Lecturer"
),
"start_date" => "2005-06-17"
)
),
"education" => Array
(
"0" => Array
(
"school" => Array
(
"id" => "193563427344550",
"name" => "Mehran Model Sec School"
),
"type" => "High School"
),
"1" => Array
(
"concentration" => Array
(
"0" => Array
(
"id" => "104076956295773",
"name" => "Computer Science"
)
),
"school" => Array
(
"id" => "113340788773685",
"name" => "Sir Adamjee Institute"
),
"type" => "College",
"year" => Array
(
"id" => "118118634930920",
"name" => "2012"
)
),
"2" => Array
(
"concentration" => Array
(
"0" => Array
(
"id" => "104076956295773",
"name" => "Computer Science"
)
),
"degree" => Array
(
"id" => "519451718218292",
"name" => "Bachelor of science in Computer Science in Computer Science"
),
"school" => Array
(
"id" => "107345492681211",
"name" => "SZABIST"
),
"type" => "Graduate School",
"year" => Array
(
"id" => "127342053975510",
"name" => "2016"
)
)
),
"id" => "145864899647476"
);
这是我的代码:
$keys = array_keys($profile);
print_r($keys);
echo count($profile);
echo "<br>";
for ($i=4; $i <count($profile)-1 ; $i++) {
# code...
/*[4] => work [5] => education*/
echo $keys[$i]."<br>";
foreach ($profile[$keys[$i]] as $k => $v) {
# code...
echo "<br>$k<br>";
$keeys=array_keys($v);
print_r($keeys);
}
}
$keys=array\u keys($profile);
打印(钥匙);
回波计数($profile);
回声“
”;
对于($i=4;$i工作[5]=>教育*/
回显$keys[$i]。“
”;
foreach($profile[$keys[$i]]作为$k=>$v){
#代码。。。
回声“
$k
”;
$keeys=数组_键($v);
印刷费($keeys);
}
}
那么…您的问题是什么?您需要访问数组以获取所需的2条信息?是的,我需要position=>name from work array和school=>name and type from education array的值。