如何在多维三维数组中获得唯一值



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

$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

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

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

<?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>";}
}

最新更新