如何在 foreach 中使用 array_keys
我需要从 array_keys 获取数据 我在服务器端使用的脚本:
PHP:
$friends = json_decode(file_get_contents(
'https://graph.facebook.com/me/friends?access_token=' .
$facebook->getAccessToken() ), true);
$friend_ids = array_keys($friends);
数组的数据如上所示:
{
"data": [
{
"name": "Tal Rozner",
"id": "554089741"
},
{
"name": "Daniel Kagan",
"id": "559274789"
},
{
"name": "ron cohen",
"id": "100001553261234"
}
]
}
我需要将所有这些数据获取到一个我可以使用它的数组。
我该怎么做? 坦克,
i need to get data from array_keys
the script i use in the server side:
PHP:
$friends = json_decode(file_get_contents(
'https://graph.facebook.com/me/friends?access_token=' .
$facebook->getAccessToken() ), true);
$friend_ids = array_keys($friends);
the data of array look as above:
{
"data": [
{
"name": "Tal Rozner",
"id": "554089741"
},
{
"name": "Daniel Kagan",
"id": "559274789"
},
{
"name": "ron cohen",
"id": "100001553261234"
}
]
}
i need to get all this data to an array that i can work with it.
how can i do it ?
tanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解你的问题(我不确定我是否理解),你可能想要类似的东西,
它会给你和看起来像这样的数组:
这可能更容易让你使用......
If i understand your question correctly (and I am not sure that I do) you might want something like
Which will give you and array that looks like this:
Which might be easier for you to work with...
不确定你的意思是“使用它”。如果来自 Facebook 的 JSON 响应是您发布的内容,您应该能够执行以下操作:
这将产生:
由于您使用了
json_decode(),
。在这种情况下,不需要$friends
var 已经是一个数组了array_keys()
,它只会生成array (0, 1, 2)
。Not sure what you mean "work with it." If the JSON response from Facebook is what you posted, you should be able to do this:
This would produce:
The
$friends
var would already be an array due to your use ofjson_decode()
. In this casearray_keys()
isn't needed, and would only producearray (0, 1, 2)
.