-2

我有以下数组:

$t[0] = array('one'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));
$t[1] = array('two'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));
$t[2] = array('one'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));
$t[3] = array('three'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));

我想从上面的数组中删除重复的数组,结果应该是:

$t[0] = array('one'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));
$t[1] = array('two'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));
$t[2] = array('three'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));

谢谢

4

2 回答 2

5
$t[0] = array('one'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));
$t[1] = array('two'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));
$t[2] = array('one'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));
$t[3] = array('three'=>array('a'=>2,'b'=>3,'c'=>2,'e'=>4));

$array = array();
foreach ($t as $key=>$value) {
    if (!in_array ($value, $array)) {
        $array [$key] = $value;
    }
}
print_r ($array);
于 2012-05-15T14:21:27.420 回答
0

据我了解,您想要做的是从多维数组中删除重复的键。

这样的事情应该可以解决问题:

$new_array = array();
foreach($t as $array) {
    foreach($array as $k => $v) {
        if(!array_key_exists($k, $new_array)) {
            $new_array[$k] = $v;
        }
    }
}
于 2012-05-15T14:37:21.327 回答