2012-05-08 266 views
0

我不知道我怎么会改变以下数组的排序:在PHP中更改数组顺序?

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

排序标准是什么? – Eineki

+0

我需要它重新排序的第一个数组键,目前从1开始。 – SoulieBaby

回答

2

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

+0

谢谢,我会看看,看看我能想出来 – SoulieBaby

1

您可以使用array_keys()函数来提取所有键,然后从旧键到新键创建一个映射,然后使用新键构建一个新数组,使用从旧数组获取的值新的重要旧钥匙图。