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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:23:58+00:00 2026-05-25T19:23:58+00:00

function sort_searches($a, $b) { return ( (isset($b[‘Class_ID’]) && !isset($a[‘Class_ID’])) || ($b[‘Results’] && !$a[‘Results’]) ||

  • 0
function sort_searches($a, $b)
{
    return
    (
        (isset($b['Class_ID']) && !isset($a['Class_ID'])) 
        ||
        ($b['Results'] && !$a['Results']) 
        || 
        (is_array($a['Results']) && !$a['Results'] && !is_array($b['Results']))
    );
}

I’m using this function in usort(). The intended effect is that a list of searches will be sorted first by whether they have Class_IDs, and then second by results (with a non-empty array of results > results === false > results === empty array(). So a sorted set of searches would look like:

Class_ID with results
Class_ID with results === false
Class_ID with results === array()
No Class_ID with results
No Class_ID with results === false
No Class_ID with results === array()

Currently the functions sorts on results completely fine, but not on whether a search has a Class_ID.

usort($searches, 'sort_searches')
  • 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-25T19:23:59+00:00Added an answer on May 25, 2026 at 7:23 pm

    From the PHP docs:

    The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.

    Your function is not returning an integer.


    To spell it out, let’s say we wanted to write a sorting function for numbers (totally unnecessary, but for the exercise):

    function sort_nums($a, $b)
    {
        if ($a < $b) return -1; // $a is less than $b
        if ($a > $b) return 1; // $a is greater than $b
        return 0; // $a is equal to $b
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing Solr dismax search and also using this function recip(ms(NOW,PubDate),3.16e-11,1000,1000) for date
I know VS2008 has the remove and sort function for cleaning up using directives,
I am getting strange behaviour using the built-in C# List.Sort function with a custom
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
I'm using the ASP Classic ReadLine() function of the File System Object. All has
If I had this: var percentDiscount; function calculate(sale, original) { percentDiscount = Math.round(eval(((original-sale)/original) *
I was using the built-in sort function of Matlab: [temp, Idx] = sort(M,2); I
We've all seen this error before: Warning: require_once(test/blah.inc) [function.require-once]: failed to open stream: No
It seems that when using a primitive type (string, number) as the this subject
This is my current code: #include <list> #include <string> using std::string; using std::list; int

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.