更改PHP中的数组顺序?

时间:2012-05-08 06:10:23

标签: php arrays

我想知道如何更改以下数组的顺序:

Array
(
    [1] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 120
                    [hteam] => Heatherton
                    [ateam] => Dingley
                    [round] => 1
                    [catid] => Seniors
                    [date] => Saturday 14th April, 2012
                    [time] => 12:00am
                    [venue] => Heatherton Recreational Reserve
                )

            [1] => stdClass Object
                (
                    [id] => 121
                    [hteam] => Heatherton
                    [ateam] => Dingley
                    [round] => 1
                    [catid] => Reserves
                    [date] => Saturday 14th April, 2012
                    [time] => 11:45am
                    [venue] => Heatherton Recreational Reserve
                )

        )

    [2] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 122
                    [hteam] => Clayton
                    [ateam] => Heatherton
                    [round] => 2
                    [catid] => Seniors
                    [date] => Saturday 21st April, 2012
                    [time] => 12:00am
                    [venue] => Clayton Reserve
                )

            [1] => stdClass Object
                (
                    [id] => 139
                    [hteam] => Clayton
                    [ateam] => Heatherton
                    [round] => 2
                    [catid] => Reserves
                    [date] => Saturday 21st April, 2012
                    [time] => 12:00am
                    [venue] => Clayton Reserve
                )
        )

    [3] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 123
                    [hteam] => Heatherton
                    [ateam] => St Pauls
                    [round] => 3
                    [catid] => Seniors
                    [date] => Saturday 28th April, 2012
                    [time] => 12:00am
                    [venue] => Heatherton Recreational Reserve
                )

            [1] => stdClass Object
                (
                    [id] => 140
                    [hteam] => Heatherton
                    [ateam] => St Pauls
                    [round] => 3
                    [catid] => Reserves
                    [date] => Saturday 28th April, 2012
                    [time] => 12:00am
                    [venue] => Heatherton Recreational Reserve
                )

        )

    [4] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 124
                    [hteam] => Mordialloc
                    [ateam] => Heatherton
                    [round] => 4
                    [catid] => Seniors
                    [date] => Saturday 5th May, 2012
                    [time] => 02:00pm
                    [venue] => Ben Kavanagh Reserve
                )

            [1] => stdClass Object
                (
                    [id] => 141
                    [hteam] => Mordialloc
                    [ateam] => Heatherton
                    [round] => 4
                    [catid] => Reserves
                    [date] => Saturday 5th May, 2012
                    [time] => 11:45am
                    [venue] => Ben Kavanagh Reserve
                )

        )
)

从^^到此:

Array
(

    [3] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 123
                    [hteam] => Heatherton
                    [ateam] => St Pauls
                    [round] => 3
                    [catid] => Seniors
                    [date] => Saturday 28th April, 2012
                    [time] => 12:00am
                    [venue] => Heatherton Recreational Reserve
                )

            [1] => stdClass Object
                (
                    [id] => 140
                    [hteam] => Heatherton
                    [ateam] => St Pauls
                    [round] => 3
                    [catid] => Reserves
                    [date] => Saturday 28th April, 2012
                    [time] => 12:00am
                    [venue] => Heatherton Recreational Reserve
                )

        )

    [4] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 124
                    [hteam] => Mordialloc
                    [ateam] => Heatherton
                    [round] => 4
                    [catid] => Seniors
                    [date] => Saturday 5th May, 2012
                    [time] => 02:00pm
                    [venue] => Ben Kavanagh Reserve
                )

            [1] => stdClass Object
                (
                    [id] => 141
                    [hteam] => Mordialloc
                    [ateam] => Heatherton
                    [round] => 4
                    [catid] => Reserves
                    [date] => Saturday 5th May, 2012
                    [time] => 11:45am
                    [venue] => Ben Kavanagh Reserve
                )

        )

        [1] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 120
                    [hteam] => Heatherton
                    [ateam] => Dingley
                    [round] => 1
                    [catid] => Seniors
                    [date] => Saturday 14th April, 2012
                    [time] => 12:00am
                    [venue] => Heatherton Recreational Reserve
                )

            [1] => stdClass Object
                (
                    [id] => 121
                    [hteam] => Heatherton
                    [ateam] => Dingley
                    [round] => 1
                    [catid] => Reserves
                    [date] => Saturday 14th April, 2012
                    [time] => 11:45am
                    [venue] => Heatherton Recreational Reserve
                )

        )

    [2] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 122
                    [hteam] => Clayton
                    [ateam] => Heatherton
                    [round] => 2
                    [catid] => Seniors
                    [date] => Saturday 21st April, 2012
                    [time] => 12:00am
                    [venue] => Clayton Reserve
                )

            [1] => stdClass Object
                (
                    [id] => 139
                    [hteam] => Clayton
                    [ateam] => Heatherton
                    [round] => 2
                    [catid] => Reserves
                    [date] => Saturday 21st April, 2012
                    [time] => 12:00am
                    [venue] => Clayton Reserve
                )
        )
)

所以在这个例子中,数组从数字3开始,到4,然后再返回到数字1 ..如果这有意义吗?任何帮助将不胜感激,谢谢:)

2 个答案:

答案 0 :(得分:2)

您可以使用usort  php函数,允许定义自己的排序函数。

答案 1 :(得分:1)

您可以使用array_keys()函数提取所有键,然后从旧键到新键进行映射,最后使用新键构造一个新数组,使用新键从旧数组中获取值钥匙旧密钥图。