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

The Archive Base Latest Questions

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

I got a 2d-array containing a column on which this whole array is to

  • 0

I got a 2d-array containing a “column” on which this whole array is to be sorted. As I learned here, it is quite straightforward using array_multisort. My problem is, that this to be sorted over column contains values that needs to be compared in an unusual way. So I thought of something like this:

function main(){
    $toBeSorted = array(array(...), ..., array(...));
    $sortColumnIndex = n;
    $sort_column = array();

    //Code copied from provided link
    foreach ($toBeSorted as $row)
        $sort_column []= $row[$sortColumnIndex];

    array_multisort($this->comparator(),$sort_column, $toBeSorted);
}

function comparator(a,b){
    return 1;
}

As you can see, I want to pass my comparator to that sort-function. I probably think to much in a non-php way.

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

    I solved it by transforming my sorting space in one, that array_multisort can handle:

    ...
    
    $sortColumn = array();
    foreach($toBeSorted as $value){
         $sortColumn[] = $this->transform($value);
    }
    array_multisort($sortColumn, $toBeSorted);
    
    ...
    

    my transformation function simply does everything I imagined the callback would do.

    function transform($value){
        //i.e. return real part of complex number
        //or parse strings or any kind of strange datatypes
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an array of CALayers containing images which can be moved around by
this is strange, I've got a macro with an array containing several registry keys.
Here is the situation: I have got the array of bytes containing the bitmap
I've got Python code with a preamble containing the line: from numpy import array,arccosh,random_integers
I got an array which I iterate over and try to create a variable.
I got an array which contains signed int data, i need to convert each
I've got an array of strings that looks like this: [noindex,nofollow] or [index, follow,
I got a 2-dimentional array containing boolean values written in C#. The cols and
I've got a bidimensional array of objects (a 2D vector containing GridCell instances) as
I've got a static class containing a static field which makes reference to a

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.