动态构造多维数组
我盯着这段代码看了将近一个半小时。由于我缺乏经验,我不知道我哪里出了问题。
$gameInfo = array(
for($i=0; $i < 10; $i++){
$friendsInfo[$i] = $facebook->api('/' . $randomfriends[$i]);
array($randomfriends[$i],
$friendsInfo[$i][first_name],
$friendsInfo[$i][last_name],
$friendsInfo[$i][hometown][name],
$friendsInfo[$i][location][name],
$friendsInfo[$i][about]
);
}
);
这是我的尝试。正如您所看到的,这些值是从 Facebook 获取的。这不是问题,因为如果我回显,每个值都会出现。我想获取这些值并将它们放入遵循此结构的多维数组中。
$gameInfo = array(
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about')
);
您能给我的任何帮助将不胜感激
I've been staring at this piece of code for nearly an hour and a half. In my inexperience I've no idea where I'm going wrong.
$gameInfo = array(
for($i=0; $i < 10; $i++){
$friendsInfo[$i] = $facebook->api('/' . $randomfriends[$i]);
array($randomfriends[$i],
$friendsInfo[$i][first_name],
$friendsInfo[$i][last_name],
$friendsInfo[$i][hometown][name],
$friendsInfo[$i][location][name],
$friendsInfo[$i][about]
);
}
);
This is my attempt. As you can see the values are being pulled in from facebook. This is not the problem as each value appears if I echo. I want to take the values and put them into a multidimensional array that follows this structure.
$gameInfo = array(
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about'),
array('first_name','last_name','hometown','location','about')
);
Any help you can give me would be greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不太确定
$facebook->api()
为您提供了什么,但您可能想要:或
更新: 如果
api()
返回JSON字符串,那么你必须使用json_decode()
< /a>:无意冒犯,但你的整个代码语法错误。您可能想阅读PHP 中的数组。
Not quite sure what
$facebook->api()
gives you, but you probably want:or
Update: If
api()
returns a JSON string, then you have to usejson_decode()
:No offense, but your whole code is wrong syntax. You might want to read about arrays in PHP.
出于好奇,该代码是否应该像 python 列表理解一样?或者是来自另一种语言?
Out of curiosity was that code supposed to be like a python list comprehension? or was it from another language?