1

I have the following 2D-Array:

Array (
[ID] => Array
    (
        [0] => 150
        [1] => 250
    )

[Group] => Array
    (
        [0] => 120
        [1] => 120
    )

[Name] => Array
    (
        [0] => Name 1
        [1] => Name 2
    )

[Price] => Array
    (
        [0] => 9.99
        [1] => 11.99
    )

[Date] => Array
    (
        [0] => 12.04.2013
        [1] => 11.04.2013
    )

[SortIndex] => Array
    (
        [0] => 20
        [1] => 10
    )

)

and I want to sort them after the SortIndex-Array ascending. But the different Values from the Arrays are related to the others. So the association can't be changed. How I could sort them?

2
  • 2
    look at array_multisort php.net/manual/en/function.array-multisort.php Commented Apr 22, 2013 at 10:29
  • 2
    Not sure if this is just my thoughts but storing an 'object' accross multiple arrays on a key index can be messy. Most people would have this more as an array of 'objects' with the values stemming off each one. This makes it easier to get/move the data. Edit: See Xpundel's answer for what I mean. Commented Apr 22, 2013 at 10:33

1 Answer 1

1

Is there is any reason not to convert array to more suitable form?

Array (
[0] => Array
    (
        [ID] => 150
        [Group] => 120
    )

[1] => Array
    (
        [ID] => 250
        [GROUP] => 120
    )
....
Sign up to request clarification or add additional context in comments.

2 Comments

Whilst this doesn't actually answer his question, I agree.
Why not... I will convert it and sort it then. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.