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 8498677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:28:05+00:00 2026-06-11T00:28:05+00:00

i have an array which is called parentArray() and is an associative array with

  • 0

i have an array which is called parentArray() and is an associative array with keys as numbers (not ordered integers) and the values which may be or may not be arrays. I have a foreach() loop which loops through the parentArray() and prints the data in html table something like this:

foreach ($parentArray as $parentkey => $childArray){
    echo "<tr>";
    $Usage = some_function1($parentkey);
    $schoolUsage = some_function2($parentkey);
    echo "<td>".$Usage."</td>";
    echo "<td>".$schoolUsage."</td>";
    echo "</tr>";
}

I need to sort the output table in increasing order of $Usage and if 2 rows have same no of $Usage then it should compare $schoolUsage and sort them in descending order. Any ideas on how to do it because i’m completely clueless. Note that $Usage and $schoolUsage are whole numbers.

  • 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-11T00:28:06+00:00Added an answer on June 11, 2026 at 12:28 am

    take a look at the function usort(). You can pass a custom function which does the sorting (bubble sort like).

    usort($parentArray, function($element1, $element2) {
      if($element1 == $element2) return 0; // elements stay on the same position as before
      if$element1 < $element2) {
        return -1; // move $element1 before element2
      } else {
        return 1; // move $element2 before element1
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array called: $fragment = array($fragment); Which has the following three values:
I have a array called $A which contains only non zero positive numbers. Now
I have a function, which is called sometimes with regular, sometimes dynamic arrays. If
I have an array which contains 12 numbers and I want to save this
I have an array which has many values in it . I just wanted
I have an array which i would like to sort it based on values
I have an array which i would like to sort it based on values
I have a class called XYZ inheriting from NSObject and an array which contains
I have an array(sorted on an attribute called node_id) of ruby objects which basically
I have an array called $type which I need to put into an SQL

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.