2014-04-30 4 views
0

foreach 루프에서 오는 배열이 여러 개 있습니다. (자세한 정보를 원하시면 내 마지막 질문을 참조 : Array values in function)을 바로 여기PHP의 배열에서 요소를 삭제하는 방법

을 :

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=Domeingebruikers,CN=Users,DC=stefan,DC=nl 
       ) 

      [0] => distinguishedname 
      [count] => 1 
      [dn] => CN=Domeingebruikers,CN=Users,DC=stefan,DC=nl 
     ) 

) 
Array 
(
    [count] => 1 
    [0] => Array 
     (
      [distinguishedname] => Array 
       (
        [count] => 1 
        [0] => CN=Gebruikers,CN=Builtin,DC=stefan,DC=nl 
       ) 

      [0] => distinguishedname 
      [count] => 1 
      [dn] => CN=Gebruikers,CN=Builtin,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=Securitygroep,OU=Securitygroups,DC=stefan,DC=nl 
       ) 

      [0] => distinguishedname 
      [count] => 1 
      [dn] => CN=Securitygroep,OU=Securitygroups,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 
     ) 

) 

가 지금은 특정 값에 대한 모든 배열을 확인하시기 바랍니다.

이 기능을 사용하여 배열을 검사하고 있습니다.

if(strpos($check[0]['distinguishedname'][0], 'OU=Test') !== false) { 

배열 중 하나가 특정 값 ("OU = 테스트")의 필요성을 포함 할 경우

그렇지 않으면 표시 할 배열은 제외되거나 숨겨 질 필요가있다. 이것을 어떻게 할 수 있습니까?

편집

이는 foreach 루프 내 코드입니다.

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

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

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

    if (strpos($check[0]['distinguishedname'][0], 'OU=Test') === false) { 

    } 
} 
+2

올바른 것으로 보입니다. 어떻게 작동하지 않습니까? –

+0

예 기능이 작동 중입니다. 하지만 특정 값을 포함하지 않는 배열을 제외하거나 숨기려면 어떻게해야합니까? 'if'와'else'? – Bale

+0

현재'! == false'를하고 있습니다. 간단하게'=== false'로 바꾸시겠습니까? –

답변

0

이게 원하는가요? foreach 루프도 변경해야합니다.

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

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

마침내! 이것은 완벽하게 작동합니다. 나는 며칠 동안 붙어 있었다. 고마워요! – Bale

+0

당신은 환영합니다 :) – Naruto