title: How to group by categories in LDAP using PHP
body: <p>How to group or arrange the results in LDAP according to "ou". OU have 4 or more categories and display it properly. How to do this with PHP and HTML? Please help me. I'm new in LDAP</p>
  
  <p>OU example</p>
  
  <pre><code>   ou=web service
     ou=department
     ou=city
  </code></pre>
  
  <p>How to do display the result like this?</p>
  
  <pre><code>   sn     dn                                        mail                 ou
     user   cn=user,ou=web service,dc=domain,dc=com   example@domain.com   web service
     sn     dn                                        mail                 ou
     user   cn=user,ou=department,dc=domain,dc=com   example@domain.com    department 
  </code></pre>
  
  <p>Here's the PHP array</p>
  
  <pre><code>  $dn = 'dc=domain,dc=com';
    $filter = "(|(sn=$person*)(fullname=$person*))";
    $ldaparray = array ("ou", "sn", "fullname", "mail");
    $sr=ldap_search($ldapconn, $dn, $filter, $ldaparray);
    $info = ldap_get_entries($ldapconn, $sr);
    echo "&lt;pre&gt;";
    print_r ($info);
    echo "&lt;/pre&gt;";
  </code></pre>
  
  <p>Output using print_r</p>
  
  <pre><code>Array
  (
  [count] =&gt; 1409
  [0] =&gt; Array
      (
          [sn] =&gt; Array
              (
                  [count] =&gt; 1
                  [0] =&gt; user
              )
  
          [0] =&gt; sn
          [count] =&gt; 1
          [dn] =&gt; cn=username,ou=web service,dc=domain,dc=com
      )
  [1] =&gt; Array
      (
          [sn] =&gt; Array
              (
                  [count] =&gt; 1
                  [0] =&gt; user
              )
  
          [0] =&gt; sn
          [mail] =&gt; Array
              (
                  [count] =&gt; 1
                  [0] =&gt; example@domain.com
              )
  
          [1] =&gt; mail
          [count] =&gt; 2
          [dn] =&gt; uid=userid,ou=department,dc=doamin,dc=com
      )
  </code></pre>