如何在这种情况下进行测试?

时间:2012-06-06 07:13:10

标签: php

有两个array s:

$tClasseMenu = array();
$tDroitsClassMenu = array();
for ($i = 0; $i < $data['user']['classMenus']['cnt']; $i++)
{
    $tClasseMenu[$i] = $data['user']['classMenus'][$i]['class_menu_code'];
    for ($j = 0; $j < $data['user']['droit']['cnt']; $j++)
    {
        $tDroitsClassMenu[$i][$j] = $data['user']['droit'][$j]['class_menu_code'];
    }
}

来自这些数组的数据示例如下:

class_menu_code = 7 , droit classmenucode = 6
class_menu_code = 7 , droit classmenucode = 6
class_menu_code = 7 , droit classmenucode = 6
class_menu_code = 7 , droit classmenucode = 6
class_menu_code = 7 , droit classmenucode = 6
class_menu_code = 7 , droit classmenucode = 4
class_menu_code = 7 , droit classmenucode = 4
class_menu_code = 7 , droit classmenucode = 4
class_menu_code = 7 , droit classmenucode = 4
class_menu_code = 7 , droit classmenucode = 4
class_menu_code = 7 , droit classmenucode = 2
class_menu_code = 7 , droit classmenucode = 2
class_menu_code = 7 , droit classmenucode = 2
class_menu_code = 7 , droit classmenucode = 2
class_menu_code = 7 , droit classmenucode = 2
class_menu_code = 7 , droit classmenucode = 2
class_menu_code = 8 , droit classmenucode = 6
class_menu_code = 8 , droit classmenucode = 6
class_menu_code = 8 , droit classmenucode = 6
class_menu_code = 8 , droit classmenucode = 6
class_menu_code = 8 , droit classmenucode = 6
class_menu_code = 8 , droit classmenucode = 4
class_menu_code = 8 , droit classmenucode = 4
class_menu_code = 8 , droit classmenucode = 4
class_menu_code = 8 , droit classmenucode = 4
class_menu_code = 8 , droit classmenucode = 4
class_menu_code = 8 , droit classmenucode = 2
class_menu_code = 8 , droit classmenucode = 2
class_menu_code = 8 , droit classmenucode = 2
class_menu_code = 8 , droit classmenucode = 2
class_menu_code = 8 , droit classmenucode = 2
class_menu_code = 8 , droit classmenucode = 2
class_menu_code = 3 , droit classmenucode = 6
class_menu_code = 3 , droit classmenucode = 6
class_menu_code = 3 , droit classmenucode = 6
class_menu_code = 3 , droit classmenucode = 6
class_menu_code = 3 , droit classmenucode = 6
class_menu_code = 3 , droit classmenucode = 4
class_menu_code = 3 , droit classmenucode = 4
class_menu_code = 3 , droit classmenucode = 4
class_menu_code = 3 , droit classmenucode = 4
class_menu_code = 3 , droit classmenucode = 4
class_menu_code = 3 , droit classmenucode = 2
class_menu_code = 3 , droit classmenucode = 2
class_menu_code = 3 , droit classmenucode = 2
class_menu_code = 3 , droit classmenucode = 2
class_menu_code = 3 , droit classmenucode = 2
class_menu_code = 3 , droit classmenucode = 2
class_menu_code = 1 , droit classmenucode = 6
class_menu_code = 1 , droit classmenucode = 6
class_menu_code = 1 , droit classmenucode = 6
class_menu_code = 1 , droit classmenucode = 6
class_menu_code = 1 , droit classmenucode = 6
class_menu_code = 1 , droit classmenucode = 4
class_menu_code = 1 , droit classmenucode = 4
class_menu_code = 1 , droit classmenucode = 4
class_menu_code = 1 , droit classmenucode = 4
class_menu_code = 1 , droit classmenucode = 4
class_menu_code = 1 , droit classmenucode = 2
class_menu_code = 1 , droit classmenucode = 2
class_menu_code = 1 , droit classmenucode = 2
class_menu_code = 1 , droit classmenucode = 2
class_menu_code = 1 , droit classmenucode = 2
class_menu_code = 1 , droit classmenucode = 2
class_menu_code = 5 , droit classmenucode = 6
class_menu_code = 5 , droit classmenucode = 6
class_menu_code = 5 , droit classmenucode = 6
class_menu_code = 5 , droit classmenucode = 6
class_menu_code = 5 , droit classmenucode = 6
class_menu_code = 5 , droit classmenucode = 4
class_menu_code = 5 , droit classmenucode = 4
class_menu_code = 5 , droit classmenucode = 4
class_menu_code = 5 , droit classmenucode = 4
class_menu_code = 5 , droit classmenucode = 4
class_menu_code = 5 , droit classmenucode = 2
class_menu_code = 5 , droit classmenucode = 2
class_menu_code = 5 , droit classmenucode = 2
class_menu_code = 5 , droit classmenucode = 2
class_menu_code = 5 , droit classmenucode = 2
class_menu_code = 5 , droit classmenucode = 2
class_menu_code = 6 , droit classmenucode = 6
class_menu_code = 6 , droit classmenucode = 6
class_menu_code = 6 , droit classmenucode = 6
class_menu_code = 6 , droit classmenucode = 6
class_menu_code = 6 , droit classmenucode = 6
class_menu_code = 6 , droit classmenucode = 4
class_menu_code = 6 , droit classmenucode = 4
class_menu_code = 6 , droit classmenucode = 4
class_menu_code = 6 , droit classmenucode = 4
class_menu_code = 6 , droit classmenucode = 4
class_menu_code = 6 , droit classmenucode = 2
class_menu_code = 6 , droit classmenucode = 2
class_menu_code = 6 , droit classmenucode = 2
class_menu_code = 6 , droit classmenucode = 2
class_menu_code = 6 , droit classmenucode = 2
class_menu_code = 6 , droit classmenucode = 2
class_menu_code = 4 , droit classmenucode = 6
class_menu_code = 4 , droit classmenucode = 6
class_menu_code = 4 , droit classmenucode = 6
class_menu_code = 4 , droit classmenucode = 6
class_menu_code = 4 , droit classmenucode = 6
class_menu_code = 4 , droit classmenucode = 4
class_menu_code = 4 , droit classmenucode = 4
class_menu_code = 4 , droit classmenucode = 4
class_menu_code = 4 , droit classmenucode = 4
class_menu_code = 4 , droit classmenucode = 4
class_menu_code = 4 , droit classmenucode = 2
class_menu_code = 4 , droit classmenucode = 2
class_menu_code = 4 , droit classmenucode = 2
class_menu_code = 4 , droit classmenucode = 2
class_menu_code = 4 , droit classmenucode = 2
class_menu_code = 4 , droit classmenucode = 2
class_menu_code = 2 , droit classmenucode = 6
class_menu_code = 2 , droit classmenucode = 6
class_menu_code = 2 , droit classmenucode = 6
class_menu_code = 2 , droit classmenucode = 6
class_menu_code = 2 , droit classmenucode = 6
class_menu_code = 2 , droit classmenucode = 4
class_menu_code = 2 , droit classmenucode = 4
class_menu_code = 2 , droit classmenucode = 4
class_menu_code = 2 , droit classmenucode = 4
class_menu_code = 2 , droit classmenucode = 4
class_menu_code = 2 , droit classmenucode = 2
class_menu_code = 2 , droit classmenucode = 2
class_menu_code = 2 , droit classmenucode = 2
class_menu_code = 2 , droit classmenucode = 2
class_menu_code = 2 , droit classmenucode = 2
class_menu_code = 2 , droit classmenucode = 2
class_menu_code = , droit classmenucode = 6
class_menu_code = , droit classmenucode = 6
class_menu_code = , droit classmenucode = 6
class_menu_code = , droit classmenucode = 6
class_menu_code = , droit classmenucode = 6
class_menu_code = , droit classmenucode = 4
class_menu_code = , droit classmenucode = 4
class_menu_code = , droit classmenucode = 4
class_menu_code = , droit classmenucode = 4
class_menu_code = , droit classmenucode = 4
class_menu_code = , droit classmenucode = 2
class_menu_code = , droit classmenucode = 2
class_menu_code = , droit classmenucode = 2
class_menu_code = , droit classmenucode = 2
class_menu_code = , droit classmenucode = 2
class_menu_code = , droit classmenucode = 2

如何测试$ tDroitsClassMenu中是否存在$ tClasseMenu中的值?

1 个答案:

答案 0 :(得分:1)

PHP的原生array_intersect函数会告诉您一个数组中的哪些值出现在另一个数组中:

$result = array_intersect( $tClassMenu, $tDroitsClassMenu );

如果$result为空,则表示没有相交点。否则,$result将填充两个阵列之间相交的所有点。

来源:http://php.net/manual/en/function.array-intersect.php