1

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

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

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

Can someone please help me with this? Thanks.

3
  • 1
    Could we get the output in text, rather than an image? I've got a script that formats it. Commented Jun 25, 2012 at 13:03
  • To me, it's just neccessary to output the names.. if it's in text format it's okay! Commented Jun 25, 2012 at 13:04
  • 1
    I'd still like the output as text. Commented Jun 25, 2012 at 13:05

2 Answers 2

1

This should work.

$dataArray = $fbfriendlikes[$data['id']]['data'];
$result = "";
foreach($dataArray as $item){
    $result .= " ".$item['name'];
}
Sign up to request clarification or add additional context in comments.

9 Comments

so, if i do return result, it's suppose to give me the names?.. Thanks!
$result should be a numerically-indexed array that contains the names from $fbfriendlikes.
If this answer helped, don't forget that you can accept it. You even get rep for accepting an answer! stackoverflow.com/faq#howtoask
Hey, i'm having this problem here: syntax error, unexpected '[', expecting ']'
Hey, one question, i seem to have a little problem, all i get from this is an output which says Array
|
0

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

5 Comments

Hi Joao, thanks for the answer, i just need to output friends likes, the names of the pages.. does you code do this?
Sorry i misinterpreted the 'name' concept. Thought it refered to friends' names. This will give you an array with the name of the likes, yes.
Can you please do me this last favor? I need to store all names in a variable $result, because the module retrurn the $result! Can you please insert this one?
I believe this is it. Test it, because the image for the array you provided is quite hard to read.
Thanks for the help, the logic seems to be pure :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.