我試圖做一些功能,會發現(在下面的數組中)的id爲2的對象,並將其移動到數組的頂部。這裏的原始數組:多維數組,找到物品並移動到頂部?
Array
(
[0] => stdClass Object
(
[id] => 177
[startdate] => 2014-08-02
)
[1] => stdClass Object
(
[id] => 178
[startdate] => 2014-08-02
)
[2] => stdClass Object
(
[id] => 2
[startdate] => 2014-07-28
)
[3] => stdClass Object
(
[id] => 82
[startdate] => 2014-07-28
)
[4] => stdClass Object
(
[id] => 199
[startdate] => 2013-10-10
)
)
這裏是什麼我也想輸出(與移動數組項):
Array
(
[0] => stdClass Object
(
[id] => 2
[startdate] => 2014-07-28
)
[1] => stdClass Object
(
[id] => 177
[startdate] => 2014-08-02
)
[2] => stdClass Object
(
[id] => 178
[startdate] => 2014-08-02
)
[3] => stdClass Object
(
[id] => 82
[startdate] => 2014-07-28
)
[4] => stdClass Object
(
[id] => 199
[startdate] => 2013-10-10
)
)
任何幫助,將不勝感激。
我才意識到,數組鍵也是2,我不希望它來移動,我需要它來移動一個是[ID] => 2 .. –
不要在編輯問題評論,把你的編輯放在問題中。你已經嘗試了什麼? –
比較(當不需要查看內部數組時):http://stackoverflow.com/a/27217431/1333493 – Nemo