Search code examples
phparraysmultidimensional-arrayadldap

Check value in multidimensional array


Here is my out put array:

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
        )

)

And this is the php code for the array:

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

Now I want to check if the value "OU=Test" exists in the [1] => member part of the array. How can I achieve this? I googled and searched on stackoverflow but don't came up with a solution. Your help is welcome.


Solution

  • try this code

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

    and if this not help you at all, please update your question and add more details, so we can understand.

    cheers!