1

有两个array

$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

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

4

1 回答 1

1

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

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

如果$result为空,则您没有相交点。否则,$result将填充两个数组之间相交的所有点。

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

于 2012-06-06T07:19:41.787 回答