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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:15:32+00:00 2026-05-17T21:15:32+00:00

Hi I have to sort this array in desc. order on the basis of

  • 0

Hi I have to sort this array in desc. order on the basis of ratingVal using php. How can I do that.

Array
(
    [0] => Array
        (
            [rating_postid] => 26
            [raCnt] => 6
            [sRate] => 18
            [ratingVal] => 3
        )

    [1] => Array
        (
            [rating_postid] => 714
            [raCnt] => 3
            [sRate] => 14
            [ratingVal] => 4.6666666666667
        )

    [2] => Array
        (
            [rating_postid] => 14
            [raCnt] => 4
            [sRate] => 12
            [ratingVal] => 3
        )

    [3] => Array
        (
            [rating_postid] => 290
            [raCnt] => 2
            [sRate] => 10
            [ratingVal] => 5
        )

    [4] => Array
        (
            [rating_postid] => 194
            [raCnt] => 2
            [sRate] => 8
            [ratingVal] => 4
        )

    [5] => Array
        (
            [rating_postid] => 134
            [raCnt] => 2
            [sRate] => 6
            [ratingVal] => 3
        )

    [6] => Array
        (
            [rating_postid] => 707
            [raCnt] => 1
            [sRate] => 5
            [ratingVal] => 5
        )

)
  • 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-17T21:15:32+00:00Added an answer on May 17, 2026 at 9:15 pm

    Use usort:

    function sortIt( $a, $b ){
        return $b['ratingVal'] - $a['ratingVal'];
    }
    
    usort( $yourArray, "sortIt" );
    

    For ascending order, swap the $a and $b in the subtraction.

    The usort function allows you to create your own custom sort function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of makefile that has this sort of structure: bob: ifdef
I have YAML data that looks sort of like this, but ~150k of it:
I have this big data-entry sort of page, a table kind of layout using
There have been a couple of questions that sort of dealt with this but
I have a query something like this: SELECT title, desc, date FROM tablename ORDER
with reference of this question Sort json array I have the following JSON String
This is sort of SQL newbie question, I think, but here goes. I have
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I have a sort of tree structure that represent a hierarchy of layers in
I have to sort a number of integers, which can have values between 30.000.000

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.