从php的关联数组中消除具有相同值的重复键


Array
(
    [0] => Zimbabwe
    [country] => Zimbabwe
    [1] => 2
    [counts] => 2
)
Array
(
    [0] => Tunisia
    [country] => Tunisia
    [1] => 6
    [counts] => 6
)   
I want output like below:  
Array
(
    [country] => Zimbabwe 
    [counts] => 2
)  
Array
(
    [country] => Tunisia   
    [counts] => 6
)

试着用

从数据库中获取
while($rowCountry = mssql_fetch_array($resultCountryCount), MSSQL_ASSOC){
    print_r($rowCountry);
}

while($rowCountry = mssql_fetch_assoc($resultCountryCount)){
    print_r($rowCountry);
}

最好使用@mark,否则您也可以尝试这个

  $a = Array
    (
        0 => 'Zimbabwe',
        'country' => 'Zimbabwe',
        1=> 2,
        'counts' => 2,
    );
    function myfun($array){
        $check= array();
        foreach($array as $k => $v){
            if(in_array($v,$check)){
                unset($array[$k]);
            }   
            array_push($check, $v);
        }
        return $array;
    }
    $a = myfun($a);
    echo '<pre>';
    print_r($a);

相关内容

  • 没有找到相关文章

最新更新