php array, loop to get the exact value

后端 未结 2 1843
慢半拍i
慢半拍i 2021-01-29 12:09

I have this code right here, where the $friends variable is an array with an output like this:

{
  \"id\": \"1149862205\",
  \"name\": \"name\",
           


        
2条回答
  •  有刺的猬
    2021-01-29 12:54

    You need to check inside you loop to get the ones that don't like.

    $return = '';
    $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'); 
            $fbname = $data['name'];
            $path = $protocol . '://graph.facebook.com/' . $fbid . '/picture?type=' . $size;
            $image = theme('image', array('path' => $path, 'alt' => $fbname));
    
            foreach($fbfriendlikes['data'] as $like) {
                $likes = false; // set var to check for like
                if($like['id'] == '184759054887922') { // check if they liked it
                    $likes = true; // set var to true because they liked it
                }
                if (!$likes) { // test var to see if false (they did not like)
                    // print this if they did NOT like it, otherwise do nothing
                    $return .= '
    '.$image.'
    '; $link = ''.$fbname.''; $return .= ''; } }// go on to next in loop } echo $return; }

提交回复
热议问题