Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:21:17+00:00 2026-06-05T19:21:17+00:00

What I have here is a PHP page working with the Facebook API. What

  • 0

What I have here is a PHP page working with the Facebook API.

What I’m trying to do is (after permissions are set by the user), to get the user’s friends’ user IDs via: $facebook->api('/me/friends'). The problem is, I would only like to get random 10 friends. I could easily limit results to 10 by using /me/friends?limit=10, but then again that wouldn’t be random.

So here is what I have right now:

     $friendsLists = $facebook->api('/me/friends');

     function getFriends($friendsLists){
       foreach ($friendsLists as $friends) {
          foreach ($friends as $friend) {
             // do something with the friend, but you only have id and name
             $id = $friend['id'];
             $name = $friend['name'];
        shuffle($id);
     return "@[".$id.":0],";
          }
       }
     }

$friendsies = getFriends($friendsLists);
$message = 'I found this Cover at <3 '.$Link.'

'.$friendsies.' check it out! :)';

I have tried shuffle(), and the first option from here: https://stackoverflow.com/a/1656983/1399030, but I think I could be doing something wrong because they don’t return anything. I’m pretty sure I’m close, but what I’ve tried so far is not working. Can it be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:21:19+00:00Added an answer on June 5, 2026 at 7:21 pm

    you’ll want to use the shuffle before you foreach, so that you actually shuffle the array.

    after that, you’ll want to limit to 10 friends. I’d suggest adding an $i var to count to ten, and adding to a new array.

    Something like this:

    function getFriends($friendsLists){
       $formatted_friends = array();
       $i = 0;
       foreach ($friendsLists as $friends) {
          // I'm guessing we'll need to shuffle here, but might also be before the previous foreach
          shuffle($friends);
          foreach ($friends as $friend) {
             // do something with the friend, but you only have id and name
             // add friend as one of the ten
             $formatted_friends[$i] = $friend;
             // keep track of the count
             $i++;
             // once we hit 10 friends, return the result in an array
             if ($i == 10){ return $formatted_friends; }
          }
       }
     }
    

    keep in mind though that it’ll return an array and not a string that you can use in an echo. If you want, you can put this in an echo for debugging purposes:

    echo 'friends: '.print_r($friendsies, true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing w php web site. Here I have set a php cookie
I have an issue going on here. I am using PHP to get values
Trying to have my PHP script return some SQL table queries. Here's my script
I am modifying my PHP network's code to have user roles like wordpress here
I have a Php page the code for which is below, I am trying
I am working on a project with PHP. I have a php page which
I have asked here why my page was not working in IE. The answer
i'm trying use facebook API to upload photo in my fan page. I downloaded
Here I have a simple php script which displays some values from a database
I am developing a php web site. Here I have implemented clean URL using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.