我有这个数组
Array
(
[0] => Array
(
[0] => A
[1] => B
[2] => C
)
[1] => Array
(
[0] => A
[1] => C
[2] => B
)
[2] => Array
(
[0] => B
[1] => A
[2] => C
)
[3] => Array
(
[0] => B
[1] => C
[2] => A
)
)
每个数组中的内容是相似的,是否可以将它们合并并拥有如下所示的单个数组?
Array
(
[0] => Array
(
[0] => A
[1] => B
[2] => C
)
)
是否有处理此功能的php函数?
答案 0 :(得分:1)
<?php
$a = array(
array('A', 'B', 'C'),
array('A', 'C', 'B'),
array('B', 'A', 'C'),
array('B', 'C', 'A')
);
$c = array();
foreach ($a as $b) {
if (! empty($b)) {
foreach ($b as $d) {
$c[] = $d;
}
}
}
$c = array_unique($c);
echo '<pre>';print_r($c);echo '</pre>';
?>
<强>输出:强>
Array
(
[0] => A
[1] => B
[2] => C
)
答案 1 :(得分:1)
是的,有可能:
array_unique (call_user_func_array ('array_merge', $yourArray));
您不需要创建自定义功能,这是一个工作示例:
$a = array(
array('a','b','c'), array('b','c','a'), array('a','c','b')
);
$x = array_unique (call_user_func_array ('array_merge', $a));
var_dump($x);
答案 2 :(得分:0)
您可以执行以下操作:
$final = $newArr = array();
foreach ($a as $val) {
foreach ($val as $value)
$newArr[] = $value;
}
$final = array_unique($newArr);
print_r($final);