如何在多维3D数组中获得独特的价值?

时间:2015-09-01 13:28:10

标签: php arrays sorting multidimensional-array

如何从多维数组获取唯一值?

$arr = array(
    array(
        array("avg"),
        array("responsecnt"),
        "other" => array ("surveycomplete"),
    ),
    array(
        array("avg","responsecnt"),
        array("responsecnt"),
        "other" => array ("surveycomplete"),
    ),
    array(
        array("avg","abc"),
        array("responsecnt","xyz"),
        "other" => array ("surveycomplete", "yes"),
    ),
    array(
        array("avg"),
        array("responsecnt"),
        "other" => array ("surveycomplete"),
    )
);
echo "<pre>";
print_r($arr);
//find unique value

我需要一些方法来在上面的数组中找到唯一值。有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

运行此脚本,我想你会看到如何做你想做的事。

<?php
$arr = array(
    array(
        array("avg"),
        array("responsecnt"),
        "other" => array ("surveycomplete")
    ),
    array(
        array("avg","responsecnt"),
        array("responsecnt"),
        "other" => array ("surveycomplete")
    ),
    array(
        array("avg","abc"),
        array("responsecnt","xyz"),
        "other" => array ("surveycomplete", "yes"),
    ),
    array(
        array("avg"),
        array("responsecnt"),
        "other" => array ("surveycomplete"),
    )
);
echo "<pre>";
print_r($arr);

for($i=0;$i<sizeof($arr);$i++){
    for($j=0;$j<sizeof($arr[$i]);$j++){
        for($k=0;$k<sizeof($arr[$i][$j]);$k++){
            echo $arr[$i][$j][$k]."<br>";
        }
    }
    for($l=0;$l<sizeof($arr[$i]["other"]);$l++)
    {echo $arr[$i]["other"][$l]."<br>";}
}