【发布时间】:2011-08-28 12:49:03
【问题描述】:
我有一个数组:
Array(
[0] => Array(
['title'] => 'Apple',
['type'] => '1'
),
[1] => Array(
['title'] => 'Oranage',
['type'] => '2'
),
[2] => Array(
['title'] => 'Tomato',
['type'] => '1'
),
//when compares with [0], 'type' is equal and both contains 'Apple', remove.
[3] => Array(
['title'] => 'Red Apple',
['type'] => '1'
),
[4] => Array(
['title'] => 'Big Tomato',
['type'] => '3'
),
//when compares with [1], 'type' is equal and both contains 'Oranage', remove.
[5] => Array(
['title'] => 'Sweet Oranage',
['type'] => '2'
)
);
如果 'type' 元素相等,而 'title' 元素包含相同的字符串([0] 和 [3] 包含 'Apple'),则仅使用一个元素。 结果将是:
Array(
[0] => Array(
['title'] => 'Apple',
['type'] => '1'
),
[1] => Array(
['title'] => 'Oranage',
['type'] => '2'
),
[2] => Array(
['title'] => 'Tomato',
['type'] => '1'
),
[4] => Array(
['title'] => 'Big Tomato',
['type'] => '3'
)
);
如何过滤这个,我很困惑。 谢谢。
【问题讨论】:
-
我不太明白这个逻辑。 [2] 和 [5] 的相似之处以及标题的相同之处...?
-
您说
'title' element in each second level array are the same ([2] and [5])- 但第二个元素的标题为Tomato,第五个元素的标题为Sweet Orange。你能澄清一下吗? -
@deceze 我看到我们在理解 [2] 和 [5] 之间的相似性方面都有问题;)
-
哦,对不起。我修改了那个。如果任一 'title' 元素包含相同的字符串,并且 'type' 元素相等。然后只剩下一个元素。