检查多维数组中的值

时间:2014-04-29 09:33:14

标签: php arrays multidimensional-array adldap

这是我的输出数组:

Array
(
    [count] => 1
    [0] => Array
        (
            [cn] => Array
                (
                    [count] => 1
                    [0] => Testgroep
                )

            [0] => cn
            [member] => Array
                (
                    [count] => 5
                    [0] => CN=Hans Hansen,OU=Test,DC=stefan,DC=nl
                    [1] => CN=Jaap Jaapen,OU=Test,DC=stefan,DC=nl
                    [2] => CN=Peter Petersen,OU=Test,DC=stefan,DC=nl
                    [3] => CN=Piet Pietersen,OU=Test,DC=stefan,DC=nl
                    [4] => CN=Administrator,CN=Users,DC=stefan,DC=nl
                )

            [1] => member
            [distinguishedname] => Array
                (
                    [count] => 1
                    [0] => CN=Testgroep,OU=Test,DC=stefan,DC=nl
                )

            [2] => distinguishedname
            [samaccountname] => Array
                (
                    [count] => 1
                    [0] => Testgroep
                )

            [3] => samaccountname
            [objectcategory] => Array
                (
                    [count] => 1
                    [0] => CN=Group,CN=Schema,CN=Configuration,DC=stefan,DC=nl
                )

            [4] => objectcategory
            [count] => 5
            [dn] => CN=Testgroep,OU=Test,DC=stefan,DC=nl
        )

)

这是数组的php代码:

$result = $adldap->group()->info('Testgroep');

现在我想检查数组的[1] => member部分中是否存在值“OU = Test”。我怎样才能做到这一点?我用Google搜索并搜索了stackoverflow,但没有提出解决方案。欢迎您的帮助。

1 个答案:

答案 0 :(得分:0)

试试这段代码

if(strpos($result[0]['distinguishedname'][0], 'OU=Test') !== false) {
    //yep!
}

如果这对您没有帮助,请更新您的问题并添加更多详细信息,以便我们了解。

喝彩!