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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:53:02+00:00 2026-06-17T20:53:02+00:00

When I try to apply the below code from here usort($myArray, function($a, $b) {

  • 0

When I try to apply the below code from here

usort($myArray, function($a, $b) {
    return $a['order'] - $b['order'];
});

it gives me results in ascending order.

Output:

0
0
0
0
0
0.29
1.09
6.33

On swapping $a and $b it gives the results in descending order except one value

usort($myArray, function($a, $b) {
    return $b['order'] - $a['order'];
});

Output:

6.33
1.09
0
0
0
0
0.29
0

i want to have the results in the below order:

6.33
1.09
0.29
0
0
0
0
0

How do i achieve the same.?

  • 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-17T20:53:03+00:00Added an answer on June 17, 2026 at 8:53 pm

    My first guess is that usort expects an integer response, and will round off your return values if they are not integers. In the case of 0.29, when it is compared to 0, the result is 0.29 (or -0.29), which rounds off to 0. For usort, 0 means the two values are equal.

    Try something like this instead:

    usort($myArray, function($a, $b) {
        if($a['order']==$b['order']) return 0;
        return $a['order'] < $b['order']?1:-1;
    });
    

    (I think that’s the correct direction. To reverse the order, change the < to >)

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

Sidebar

Related Questions

I am getting the error message below when I try to compile any code.
I want to call this function from OpenSSL library defined with prototy below: X509
I tried the code below to run a stand-alone utility app I created from
consider the code below: -module(except). -compile(export_all). divone(X)-> erlang:error({badnews,erlang:get_stacktrace()}),1/X-1. tryreturn(X)-> try divone(X) of Val->{result,2/Val} catch
Here's a bit of javascript taken from this reddit post : function Stream() {
The Emacs code for apply-partially is this: (defun apply-partially (fun &rest args) Return a
I keep getting 21002 'java.lang.NullPointerException' errors from Apple when I try to test my
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
When copying and pasting a bit of sample code from MSDN, I came up

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.