爲了我有一個數組:移動特定的陣列項目陣列的開頭沒有改變其餘
Array
(
[product1] => Array
(
[id] => 1
[title] => 'p1'
[extra] => Array(
[date] => '1990-02-04 16:40:26'
)
)
[product2] => Array
(
[id] => 2
[title] => 'p2'
[extra] => Array(
[date] => '1980-01-04 16:40:26'
)
)
[product3] => Array
(
[id] => 3
[title] => 'p3'
[extra] => Array(
[date] => '2000-01-04 16:40:26'
)
)
[product4] => Array
(
[id] => 4
[title] => 'p4'
[extra] => Array(
[date] => '1995-01-04 16:40:26'
)
)
[product5] => Array
(
[id] => 5
[title] => 'p5'
[extra] => Array(
[date] => '1960-01-04 16:40:26'
)
)
...
我需要2種產品與最新的日期,並將其移動到數組的開始。
我已經看過multisort函數,並且我可以像這樣對數組進行排序,但隨後整個數組將按日期排列,我想維護數組的順序,但只是碰到最新的2行。
我需要從數組中選出2個最新的(按日期排序),然後將它們移到數組的開頭。因此,IDS的順序應該是:
3,4,1,2,5
最新2已經被移動到陣列的前端,其餘仍然由ID排序。
您可以發佈預期的輸出 –
使用array_shift() –
您能否提供一些關於您想要實現的更多信息? –