title: Why does this LDAP query return an array with just a 0
body: <p>I'm new to LDAP and Active Directory. I'm trying to fetch the Email-ID of an authenticated user using the following code. However when I run it, all I get is an array with a 0 in it.</p>
  
  <p>Here's the code</p>
  
  <pre><code>$server ='ldaps://DOMAIN'; 
  $username = 'DOMAIN\UID'; 
  $password = 'PASSWORD';
  
  $base_dn = 'dc=DOMAIN';
  $search_filter = 'dn=UID'; 
  $attributes = ['mail']; 
  
  $ldap = ldap_connect($server);
  ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  ldap_bind($ldap, $username, $password); 
  $search = ldap_search($ldap, $base_dn, $search_filter, $attributes);
  $data = ldap_get_entries($ldap, $search);
  
  foreach($data as $dataPoint)
      {
          echo $dataPoint;
          echo "&lt;hr&gt;";
      }
  </code></pre>
  
  <p>This outputs just a 0 with a horizontal line below it.</p>
  
  <p>The most challenging thing here is that there is no error message whatsoever and I'm not very familiar with LDAP nor with Active Directory.</p>
  
  <p>Any idea as to why this could be happening.</p>