我有一個多維數組這有點兒像這樣從多維數組創建獨特的數組?
Array
(
[0] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
[title_generic] =>
[text_generic] =>
)
[1] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
[title_generic] =>
[text_generic] =>
)
[2] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
[title_generic] =>
[text_generic] =>
)
[3] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
[title_generic] =>
[text_generic] =>
)
[4] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
[title_generic] => Random title
[text_generic] => [b]This is Random title:[/b] 16 nov 2012
)
[5] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
Some text goes here. Blaaaa
[title_generic] =>
[text_generic] =>
)
[6] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
[title_generic] =>
[text_generic] =>
)
)
我試着用array_unique()
過濾,但只返回
Array
(
[0] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
[title_generic] =>
[text_generic] =>
)
)
但我想有
Array
(
[0] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
Some text goes here. Blaaaa
[title_generic] => Random title
[text_generic] => [b]This is Random title:[/b] 16 nov 2012
)
)
即只返回全部填充的唯一字段。
在陣列中將只有一個唯一的填充空間,所以沒有辦法,在第一把鑰匙我會有title_generic
然後我會有不同的三分之一左右。 body
和text_generic
也是如此。它們在某些數組中只出現一次。但是ID,標題等都是一樣的(裏面有一個日期等等)。
有沒有一個功能會做這樣的事情?
編輯
我可能不太清楚。我想返回包含來自其他鍵(來自該鍵的數組中的值)的所有信息的數組,這些不同。所以在陣列中的前4個鍵中,我有與id
,headline
,body
,title_generic
和text_generic
相同的陣列。他們有相同的標識和標題,其餘都是空的。然後在下一個鍵中填入title_generic
和text_generic
,依此類推。
我需要將填補鍵,如
Array
(
[0] => Array
(
[id] => 140309
[headline] => Random title
[body] =>
Some text goes here. Blaaaa
[title_generic] => Random title
[text_generic] => [b]This is Random title:[/b] 16 nov 2012
)
)
或
Array
(
[id] => 140309
[headline] => Random title
[body] =>
Some text goes here. Blaaaa
[title_generic] => Random title
[text_generic] => [b]This is Random title:[/b] 16 nov 2012
)
任一陣列,我不知道該如何解釋這更好的...
對不起,你能用簡單的術語再次解釋邏輯嗎?你想通過某個定義返回一個「唯一」的數組嗎?或者你想將所有這些數組合併成一個字段的值由某個「唯一性」標準選擇的數組?不,沒有內置的功能。 – deceze
嗯,這取決於。如果邏輯是附加信息(例如,'title_generic','text_generic'等)不會導致衝突(多個不同的'title_generic' ...),你可以這樣做。別的,你會如何解決衝突?例如哪一個標題是正確的? –
聽起來像你想將所有信息合併到一個數組中。你必須解釋如何決定選擇哪一條信息,然後是否有多個選項(如@ F.M所說的「衝突解決方案」)。 – deceze