1

我已经阅读了 Google 上的官方文档和大量文档。我想打印用户信息,但是当我运行我的代码时,我得到了这个:

Array
(
[id] => xxxx
[name] => Vinicius 
[first_name] => Vinicius
[last_name] => M
[link] => http://www.facebook.com/xxx
[username] => vinicius
[birthday] => 01/04/1989
...

我的代码是,获取用户信息:

//if user is logged in and session is valid.
if ($user){
//get user basic description
$userInfo = $facebook->api("/$user");

并展示:

<?php d($userInfo);  ?>

我想这样打印(或类似的东西):

Name: Vinicius
Last name: M
Birthday: 01/04/1989

我遵循了 Thinkdiff 教程。他们的很多代码。

嵌套数组怎么样?

[location] => Array (
    [id] => 110703698957912
    [name] => Campinas, Sao Paulo 
)
4

1 回答 1

2

尝试这个:

echo 'First name: ' . $userInfo['first_name'];
echo 'Last name: ' . $userInfo['last_name'];
echo 'Birthday: ' . $userInfo['birthday'];

对于嵌套数组,例如:

[location] => Array (
    [id] => 110703698957912
    [name] => Campinas, Sao Paulo 
)

您可以通过以下方式访问它们:

$userInfo['location']['id'];
$userInfo['location']['name'];
于 2012-11-30T03:14:15.093 回答