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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:27:27+00:00 2026-06-10T04:27:27+00:00

Im trying to organize this kind of array array 0 => array ‘id’ =>

  • 0

Im trying to organize this kind of array

array
  0 => 
    array
      'id' => '19'
      'nome' => 'Lorem ipsum'
      'order' => '0'
  1 => 
    array
      'id' => '23'
      'nome' => 'Lorem ipsum'
      'order' => '2'
  2 => 
    array
      'id' => '45'
      'nome' => 'Lorem ipsum'
      'order' => '0'
  3 => 
    array
      'id' => '6'
      'nome' => 'Lorem ipsum'
      'order' => '0'
  4 => 
    array
      'id' => '23'
      'nome' => 'Lorem ipsum'
      'order' => '1'
  5 => 
    array
      'id' => '12'
      'nome' => 'Lorem ipsum'
      'order' => '0'

So, I have to put the zeros values in order to the end of the array, and using others order values to ordering correctely the array.

array
  0 => 
    array
      'id' => '23'
      'nome' => 'Lorem ipsum'
      'order' => '1'
  1 => 
    array
      'id' => '23'
      'nome' => 'Lorem ipsum'
      'order' => '2'
  2 => 
    array
      'id' => '19'
      'nome' => 'Lorem ipsum'
      'order' => '0'
  3 => 
    array
      'id' => '45'
      'nome' => 'Lorem ipsum'
      'order' => '0'
  4 => 
    array
      'id' => '6'
      'nome' => 'Lorem ipsum'
      'order' => '0'
  5 => 
    array
      'id' => '12'
      'nome' => 'Lorem ipsum'
      'order' => '0'

I tried using usort like this, with not the correct result:

    usort($items, function() {
        if ($a['uf_order'] == 0) return 0;
        return ($a['uf_order'] > $b['uf_order']) ? -1 : 1;
    });
  • 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-10T04:27:28+00:00Added an answer on June 10, 2026 at 4:27 am

    You have to pass $a and $b in the function:

    usort($items, function($a, $b) {
        if ($a['uf_order'] == 0) return 0;
        return ($a['uf_order'] > $b['uf_order']) ? -1 : 1;
    });
    

    Also there is no key called uf_order in your array.

    As NomikOS correctly stated in his comment. This would only work in PHP 5.3+. If you have an older version of PHP you could do:

    usort($items, 'cmp');
    
    function cmp ($a, $b) {
        if ($a['uf_order'] == 0) return 0;
        return ($a['uf_order'] > $b['uf_order']) ? -1 : 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to organize my program into functions and have ran into this,
I am trying to organize a Zip Archive into an array so that I
I have a bunch of divs I'm trying to organize here. The ones I'm
I have Python nested list that I'm trying to organize and eventually count number
I'm trying to organize my workspace and want my intermediate objects to be put
I am trying to organize my application into packages because it will have several
I am trying to organize some modules for my own use. I have something
I'm trying to work out how to organize an android application that will have
As documented here: http://www.jblotus.com/2011/05/24/keeping-your-handlebars-js-templates-organized/ I am trying to use this function: ( function getTemplateAjax(path,
I'm trying to jump through some hoops to organize data in a special way.

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.