What is the correct way to check if a LDAP search in PHP returns no results?

When performing an LDAP search in PHP, you can check if the search returns no results by examining the number of entries returned. If the count is zero, then the search did not find any matching entries. You can use the ldap_count_entries() function to get the number of entries returned by the search.

// Perform LDAP search
$search = ldap_search($ldapConnection, $baseDn, $filter);

// Check if search returned no results
if (ldap_count_entries($ldapConnection, $search) == 0) {
    echo "No results found.";
} else {
    // Process the search results
    $entries = ldap_get_entries($ldapConnection, $search);
    // Do something with the entries
}