从PHP中的多个数组中获取值

时间:2014-04-30 09:03:36

标签: php arrays

这是我的数组来自foreach循环:

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

            [0] => distinguishedname
            [count] => 1
            [dn] => CN=Administratie,OU=Test,DC=stefan,DC=nl
        )

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

            [0] => distinguishedname
            [count] => 1
            [dn] => CN=Anderemailgroep,OU=Test,DC=stefan,DC=nl
        )

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

            [0] => distinguishedname
            [count] => 1
            [dn] => CN=Beheergroep,OU=Test,DC=stefan,DC=nl
        )

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

            [0] => distinguishedname
            [count] => 1
            [dn] => CN=Belangrijke Groep,OU=Test,DC=stefan,DC=nl
        )

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

            [0] => distinguishedname
            [count] => 1
            [dn] => CN=Hoofdgroep,OU=Test,DC=stefan,DC=nl
        )

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

            [0] => distinguishedname
            [count] => 1
            [dn] => CN=Mailgroep,OU=Test,DC=stefan,DC=nl
        )

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

            [0] => distinguishedname
            [count] => 1
            [dn] => CN=Testgroep2,OU=Test,DC=stefan,DC=nl
        )

)

问题是,如何从列表中的所有数组中获取所有CN = " GroupName" 值?它只需从每个数组中获取该值并将其显示在列表中。

例如:

我只希望每个数组都有这个值。

enter image description here

输出应该是这样的:

Administratie
Anderemailgroep
Beheergroep
Belangrijke Groep
Hoofdgroep
Mailgroep
Testgroep2

修改

阵列来自这段代码:

$result = $adldap->user()->groups('test.user');

            for ($i=0;$i<count($result);$i++) {
            sort($result);
            }
            print_r($result);

    foreach ($result as $key => $value) {
    $check = $adldap->group()->info($value, array(
        'distinguishedname'
    ));

        if (strpos($check[0]['distinguishedname'][0], 'OU=Test') !== false) {
            unset($result[$key]);
            print_r($check);
        }
    }

1 个答案:

答案 0 :(得分:0)

假设您的数组是 $ arrs ,其中包含您提供的数组值。 你可以这样做。

<?php

foreach($arrs as $arr) {
   foreach($arr as $ar) {
       $sep = explode(',',$ar['dn']);
       echo explode('=',$sep[0])[1];
   }
}

?>