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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:05:36+00:00 2026-06-18T06:05:36+00:00

I have a multidimensional array similar to the one described below: Matrix => array(

  • 0

I have a multidimensional array similar to the one described below:

Matrix => array(
 [0] => array( [0] => 7, [1] => 'hello' ),
 [1] => array( [0] => 3, [1] => 'there' ),
 [2] => array( [0] => 1, [1] => 'world' ),
)

What I’m trying to achieve is to sort this array using the values of Matrix[i][0]. What would be the most efficient way to do this? I looked into the recursive QuickSort function possibility, but it’s rather complicated as I’m multidimensional arrays. There are many examples of quicksort, but none of them handle taking an “Array of Array of String” as an input.

Please ask for clarification if my text seems gibberish. I’m still fairly new to Delphi.

  • 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-18T06:05:38+00:00Added an answer on June 18, 2026 at 6:05 am

    As Rob pointed out in his comment, there’s no way to have an multi-dimensional array that stores both integers and strings (without resorting to variants).

    If it’s really just an array containing integer/string pairs, it would be much easier to store them in a TStringList using the Strings and Objects properties, and then use CustomSort to sort on the Object values:

    program Project2;
    
    {$APPTYPE CONSOLE}
    
    uses
      SysUtils, Classes;
    
    function MySortProc(List: TStringList; Index1, Index2: Integer): Integer;
    begin
      Result := Integer(List.Objects[Index1]) - Integer(List.Objects[Index2]);
    end;
    
    var
      SL: TStringList;
      i: Integer;
    begin
      SL := TStringList.Create;
      try
        for i := 0 to 10 do
          SL.AddObject(Format('Item %d', [i]),  TObject(Random(i)));
        SL.CustomSort(@MySortProc);
        for i := 0 to SL.Count - 1 do
          WriteLn(Format('%d: %s', [Integer(SL.Objects[i]), SL[i]]));
        ReadLn;
      finally
        SL.Free;
      end;
    end.
    

    This produces

    enter image description here

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

Sidebar

Related Questions

I have a multidimensional array like this one: Array ( [site1] => Array (
I have a multidimensional array, I am interested in getting all the elements (one
I have an multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array of arrays (source below), where my keys and values
I have a multidimensional array like this: array(2) { [1]=> array(3) { [eventID]=> string(1)
I have a multi-dimensional array similar to the example below that I want to
i have an multidimensional array like this Array ( [59] => stdClass Object (
I have a multidimensional array in PHP like this: $array = array( Part1 =>
I have a multidimensional array that looks like this: Array ( [0] => Array
Possible Duplicate: How do I sort a multidimensional array in php I have multidimensional

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.