按值比较php中的2个数组

I have a big problem and I have no idea how to develop this : So I have a table :

Array(
[0] => Array
    (
        [0] => Array
            (
                [host] => test1
            )

    )

[1] => Array
    (
        [0] => Array
            (
                [host] => test2
            )

    )

  )
)

And the second table

 Array
 (
    [0] => test1
    [1] => ghfhfghfg
 )

Now I want to compare this tables and retourne $nCount = 1 beacause there are 2 hosts equals from first and second table.

First of all you have to know what's your input. In your case I assumed that you will always have the same type of multi-column "table" (as you call it).

For this case you can use something like the following which flattens the multi-column array to a flat array like the second one.

<?php
$multi_col = array(
    array(
        array(
            'host'=>'test1'
        )
    ),
    array(
        array(
            'host'=>'test2'
        )
    )
);

$single_col = array('test1', 'sfsd');
$single_cold_multicol = array_map(function(Array $item){
    return $item[0]['host'];
}, $multi_col);

$diff_compare = array_diff($single_col, $single_cold_multicol);
$nCount = count($single_col) - count($diff_compare);

In case youre $multi_col does not always have the same depth, you would need to recursively flatten. If it does always have the same depth (you always know how the array is built), you can just use the code above.

You could do something like this:

count(array_intersect(array_map(function($a) { return $a[0]['host']; }, $array1), $array2));

I tend to avoid hard-coding array indices if I can help it.

Will your first array structure always be the same?

I would write a function that would flatten the first array, for example:

    function flatten($arr, &$acc=array()) {
        if (empty($arr)) {
            return $acc;
        }   
        $e = array_pop($arr);
        if (is_array($e)) {
            flatten($e, $acc);
        } else {
            $acc[] = $e;
        }
        return flatten($arr, $acc);
    }

This flatten method would work for a more general case of your first array. The calls would be something like so:

    $ar = array(
        array(
            'test1',
        ),
        array(
            'test2',
        ),
     );

     $ar2 = array(
         'test1',
         'ghfhfghfg',
     );

     $same = array_intersect(flatten($ar), $ar2);
     var_dump($same);

You can add more checks for the flatten function.