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

  • SEARCH
  • Home
  • 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 6379877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:11:41+00:00 2026-05-25T02:11:41+00:00

Basically, I have the arrays $name , $followers and $imageurl , and I would

  • 0

Basically, I have the arrays $name, $followers and $imageurl, and I would like to arrange the $followers array numerically, but also update the arrangement of $name and $imageurl accordingly.

For example, $followers[0] = 2783848, $name[0] = "Rob" and $imageurl[0] = "http://xxx.com/image.jpeg" where all three arrays are linked through having the same array key.

For good measure, here’s my whole code:

$screennames = array(
                 0 => "LilKim",
                 1 => "NickiMinaj",
                 2 => "drakkardnoir",
                 3 => "LilTunechi",
                 4 => "kanyewest",
                 5 => "RealWizKhalifa",
                 6 => "beyonce",
                 7 => "KELLYROWLAND",
                 8 => "LupeFiasco",
                 9 => "TinieTempah",
                 10 => "50cent",
                 11 => "TRINArockstarr",
                 12 => "iamdiddy",
                 13 => "Timbaland",
                 14 => "chrisbrown"
                     );

for($i = 0; $i < 15; $i++) {
$xml[$i] = @simplexml_load_file('http://api.twitter.com/1/users/show.xml?screen_name=' . $screennames[$i]);
$name[$i] = $xml[$i]->name;
$followers[$i] = $xml[$i]->followers_count;
$imageurl[$i] = $xml[$i]->profile_image_url;
}

Any advice/answers/comments will be greatly appreciated :)!!

I’m also not sure that this is the best way to query the Twitter API, so if anyone has any recommendations, feel free to leave them here :).

UPDATE:

I think I’ve found a way to put this more precisely;

I have the arrays $name, $followers and $imageurl where each value is relative, e.g. $name[0] is relative to $followers[0] and $imageurl[0]. I would like to create a fourth array $rank which contains values 1-15 ordered based on the relative value of followers, for example:

$followers = array(0 => 278738, 1 => 32784, 2 => 103562, 3 => 37848); // Etc from keys 0 - 14

$rank[0] = 1;
$rank[1] = 4;
$rank[2] = 2;
$rank[3] = 3;

That should make a lot easier to figure out what I’m looking for.

  • 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-05-25T02:11:42+00:00Added an answer on May 25, 2026 at 2:11 am

    It shouldn’t matter if you preserve your keys. For that use asort. When you loop through the name array, the values will be arranged alphabetically(or however, depending on your asort params) and the indexes (the keys, the numbers) will be out of numeric order.

    //show by name alphabetically
    asort($names); //puts names in alphabetic order, while preserving key associations
    foreach ($names as $key=>$value) {
        echo "$value has " . $followers[$key] . ' followers<br>';
    }
    
    //show ordered by most followers
    arsort($names, SORT_NUMERIC); //puts followers in reverse numeric order, while preserving key associations
    foreach ($followers as $key=>$value) {
        echo $name[$key] . ' has $value followers<br>';
    }  
    

    Update

    //Create rank array
    $rank=0;
    arsort($names, SORT_NUMERIC); //puts followers in reverse numeric order, while preserving key associations
    foreach ($followers as $key=>$value) {
      $rank++; 
      $ranks[$rank]=$key;
    }  
    

    Then you can loop through ranks, and display it, or do insert statements or whatever.

    foreach ($ranks as $rank=>$key) {
       echo "{$name[$key]} has rank $rank";
       $sql="INSERT INTO ranks ('username','followers','rank') VALUES ('{$name['$key']}','{$followers['$key']}','$rank')";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays they look like $a1 = array( array('num' => 1, 'name'
So basically I have a huge array of arrays (only a 2-d array)... My
I am learning about arrays, and basically I have an array that collects a
Basically, I have an array like this: val base_length = Array( 0, 1, 2,
I have an array like this: $_SESSION['food'] = array( array( name => apple, shape
I have two arrays one like 1 | 1st name 2 | 2nd name
I have a pretty simple problem. Basically I have an array called $list that
Basically I have this string $str=word1 word2 word3; I need array( 'word1', 'word2', 'word3'
Basically, I have an array of keywords, and a piece of text. I am
Basically, I have an array of strings to search for. If it were only

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.