Jump to content

Sorting Arrays

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
falco85

falco85

    Programmer

  • Members
  • PipPipPipPip
  • 105 posts
Is there a way to sort a multi-dimensional array?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Yes. Now, what are your criteria for the array being "sorted"?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
falco85

falco85

    Programmer

  • Members
  • PipPipPipPip
  • 105 posts
Well I have an array that looks like this:

array[0] = "data1|data2|data3|data4";
array[1] = "data1|data2|data3|data4";

I need the array sorted by data3. The only way I can think of doing it is by cycling through the array - exploding it and then adding the data to another array. Is that right?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It depends a little bit on whether you need to sort data1, data2, data4 in parallel with data3. If you need to sort data3 and not touch the others, I'd just pass data3 into your sort algorithm and be done.

Basicly, you need to find a "key" that you can sort linearly, and work everything off that as necessary.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Crane

Crane

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 398 posts
Did you ever figure this one out? I'd like to see the code results from it.

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
The problem is that I don't know PHP. And I wasn't clear what exactly needs to get sorted.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog