简体   繁体   中英

php: alphabetically sort multi-dimensional array by its key?

I need to sort some nested arrays alphabetically by their key...

Is there a native PHP function to sort the following so the nested arrays were in order like

[G] -> array...

[I] -> array...

[P] -> array...

[S] -> array...

[T] -> array...

here is an example unsorted array:

[S] => Array
    (
        [26] => Array
            (
                [name] => St Georges Hall
                [tel] => sdfa
            )

        [27] => Array
            (
                [name] => St Werburghs Community Centre
                [tel] => sadf
            )
    )

[G] => Array
    (
        [40] => Array
            (
                [name] => The Golden Guinea
                [tel] => 
            )

        [41] => Array
            (
                [name] => The Golden Lion
                [tel] => One of Bristol's key live music pubs
            )

    )

[I] => Array
    (
        [45] => Array
            (
                [name] => The Island
                [tel] => asdfgf
            )

    )

[P] => Array
    (
        [50] => Array
            (
                [name] => The Prom
                [tel] => Reliable gig venue and blues hotspot on Gloucester road
            )

    )

[T] => Array
    (
        [51] => Array
            (
                [name] => The Thunderbolt
                [tel] => Small gig venue in Totterdown
            )

        [52] => Array
            (
                [name] => Tobacco Factory
                [tel] => A modern cafe-bar with regular live music.
            )

    )

是的, ksort

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM