php通过关联数组循环 [英] php loop through associative arrays

查看:89
本文介绍了php通过关联数组循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Stackoverflow上编辑此代码,我真的可以得到我需要的结果.

Editing this code here on Stackoverflow and I'm really near to get the result I need.

所以我将这段代码发布在这里:

So I have this code posted down here:

$friends = $facebook->api('/me/friends');
if(!empty($friends['data'])){
$size = variable_get('facebook_graph_pic_size_nodes','square');
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
    foreach($friends['data'] as $data){
        $fbid = $data['id'];
        $fbfriendlikes[$fbid]=$facebook->api('/'.$fbid.'/likes'); 
    }

$fbfriendlikes向我输出一个像这样的数组: http://penelope-ns. net/fb/fig.jpg

The $fbfriendlikes outputs me an array like this one : http://penelope-ns.net/fb/fig.jpg

我需要做的是将所有名称保存在$return值中.

What do I need to do is save the names in a $return value, all names.

有人可以帮我吗? 谢谢.

Can someone please help me with this? Thanks.

推荐答案

这应该有效.

$dataArray = $fbfriendlikes[$data['id']]['data'];
$result = "";
foreach($dataArray as $item){
    $result .= " ".$item['name'];
}

这篇关于php通过关联数组循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆