简体   繁体   English

PHP通过关联数组循环

[英]php loop through associative arrays

Editing this code here on Stackoverflow and I'm really near to get the result I need. 在Stackoverflow上编辑此代码,我真的可以得到我需要的结果。

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'); 
    }

The $fbfriendlikes outputs me an array like this one : http://penelope-ns.net/fb/fig.jpg $fbfriendlikes输出给我这样的数组: http : $fbfriendlikes

What do I need to do is save the names in a $return value, all names. 我需要做的是将名称(所有名称)保存在$return值中。

Can someone please help me with this? 有人可以帮我吗? Thanks. 谢谢。

This should work. 这应该工作。

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

Is this what you want? 这是你想要的吗?

$friends = $facebook->api('/me/friends');
$result= array();
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 $key => $data){
        $fbid = $data['id'];
        $result[$key] = $data;
        $fbfriendlikes[$fbid] = $facebook->api('/'.$fbid.'/likes'); 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM