0

I need to sort my array in alphabetical order so the result should be like this:

Inn Zoo
Leo Ann
Leo Zes
Sun Yog

I looked at all these examples but can't apply to my array below(older questions):


Array
(
    [1] => Array
        (
            [Inn] => Array
                (
                    [Zoo] => Inn Zoo
                )

        )

    [2] => Array
        (
            [Sun] => Array
                (
                    [Yog] => Sun Yog
                )

        )

    [3] => Array
        (
            [Leo] => Array
                (
                    [Zes] => Leo Zes
                )

        )
    [4] => Array
        (
            [Leo] => Array
                (
                    [Ann] => Leo Ann
                )

        )
)
Community
  • 1
  • 1
BentCoder
  • 12,257
  • 22
  • 93
  • 165
  • why can't you apply it to this example? – Wouter J Mar 13 '13 at 17:39
  • 1
    possible duplicate of [How do I sort a multidimensional array in php](http://stackoverflow.com/questions/96759/how-do-i-sort-a-multidimensional-array-in-php) – jeroen Mar 13 '13 at 17:43
  • most likely because he is using the name as the key for his array. You would probably just have to do something like array_keys and get the first value then sort by that. – Jonathan Kuhn Mar 13 '13 at 17:45
  • 1
    Your array structure is very weird. Why are you using names as keys instead of using uniform keys like `first_name` and `last_name`? – Barmar Mar 13 '13 at 17:48
  • Can the subarrays ever have more than one element? – Barmar Mar 13 '13 at 17:49
  • OK, I changed the structure to `$key=>$value` by concatenating `name, surname and Full name`. `asort()` finished the job. Thanks all. – BentCoder Mar 13 '13 at 17:53

1 Answers1

-1
array
(
    [0] => Inn|Zoo|Inn Zoo
    [1] => Sunn|Yog|Sun Yog
    [2] => Leo|Zes|Leo Ann
    [3] => Leo|Ann|Leo Zes
)

asort($list);

array
(
    [0] => Inn|Zoo|Inn Zoo
    [3] => Leo|Ann|Leo Zes
    [2] => Leo|Zes|Leo Ann
    [1] => Sunn|Yog|Sun Yog
)
BentCoder
  • 12,257
  • 22
  • 93
  • 165
  • 1
    Contributor of the downvote - how do we know that you're not just one of those who swing around to randomly down vote posts for fun? – BentCoder Jan 24 '14 at 15:28