我有一个多维数组这有点儿像这样从多维数组创建独特的数组?
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