我有一個數組像這樣(抽象爲清楚起見):重複ASSOC數組值組合成一個附加的鍵
$foo = array(
'breakfast' => 'a daily meal',
'lunch' => 'a daily meal',
'dessert' => 'a special treat',
'snack' => 'a special treat',
'plates' => 'tableware'
);
爲此,我想重複值的所有鍵合併到單個「合併」關鍵 - 讓print_r($foo);
會像這樣:
Array
(
[breakfast|lunch] => 'a daily meal'
[dessert|snack] => 'a special treat'
[plates] => 'tableware'
)
目前我經歷了漫長的嵌套的一系列醜陋的foreach語句完成這個......是有更簡單的/更合適的方法?
所有這些解決方案都是比我在做什麼好,但關鍵是'array_flip' - 我錯過了這個功能,這實際上是我試圖完成的。感謝指針。 – k3davis 2012-04-13 18:09:28