douting0585 2016-08-08 10:50
浏览 39
已采纳

php中单个数组的多维数组的数组差异

I want difference of multidimensional array with single array. I dont know whether it is possible or not. But my purpose is find diference.

My first array contain username and mobile number

array1
(
array(lokesh,9687060900),
array(mehul,9714959456),
array(atish,9913400714),
array(naitik,8735081680)
)

array2(naitik,atish)

then I want as result

result( array(lokesh,9687060900), array(mehul,9714959456) )

I know the function array_diff($a1,$a2); but this not solve my problem. Please refer me help me to find solution.

  • 写回答

3条回答 默认 最新

  • doujian1954 2016-08-08 11:05
    关注

    Try this-

        $array1 = array(array('lokesh',9687060900),
        array('mehul',9714959456),
        array('atish',9913400714),
        array('naitik',8735081680));
    
        $array2 = ['naitik','atish'];
    
        $result = [];
            foreach($array1 as $val2){
    
            if(!in_array($val2[0], $array2)){
                $result[] = $val2;
            }
        }
    
    echo '<pre>';
    print_r($result);
    

    Hope this will help you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?