我有一個關聯數組作爲如何追加數組中的值,如果關鍵是相同
[name]->user1,
[class_code]->bsc,
[name]->user2,
[class_code]->msc,
[name]->user1,
[class_code]->mca
現在,我想結果爲
[name]->user1,
[class_code]->bsc,
mca
[name]->user2,
[class_code]->msc
意味着,如果名稱是相同的,則class_code追加到第一。我應該怎麼做? 我的陣列是
[1] =stdClass Object
([class_code] =Maths
[userid] =365
[avatar] =default.jpg
[username] =user2
)
[2] =stdClass Object
(
[class_code] =Maths
[userid] = 364
[avatar] =default.jpg
[username] =user1
)
[3] =stdClass Object
(
[class_code] =MCA
[userid] =364
[avatar] =default.jpg
[username] =user1
)
[4] =stdClass Object
(
[class_code] =MCA
[userid] =365
[avatar] =default.jpg
[username] =user2
)
現在,雖然顯示的結果我想顯示對前記錄。用戶2作爲
username:user2
avatar
classcode :MCA,Maths
,而不是
username:user2
avatar
classcode :MCA
username:user2
avatar
classcode :Maths
我該怎麼辦呢?
你怎麼能有一個關聯數組,其中不同的條目具有相同的密鑰?請發佈陣列的'var_export'。 – 2011-05-25 07:32:51