You are here

public static function SimpleLdap::removeEmptyAttributes in Simple LDAP 7

Same name and namespace in other branches
  1. 7.2 SimpleLdap.class.php \SimpleLdap::removeEmptyAttributes()

Cleans an attribute array, removing empty items.

Parameters

array $attributes: Array of attributes that needs to be cleaned.

boolean $strip_empty_array: Determines whether an attribute consisting of an empty array should be stripped or left intact. Defaults to TRUE.

Return value

array A scrubbed array with no empty attributes.

2 calls to SimpleLdap::removeEmptyAttributes()
SimpleLdapServer::add in ./SimpleLdapServer.class.php
Add an entry to the LDAP directory.
SimpleLdapServer::modify in ./SimpleLdapServer.class.php
Modify an LDAP entry.

File

./SimpleLdap.class.php, line 56
Class defining base Simple LDAP functionallity.

Class

SimpleLdap
Simple LDAP class.

Code

public static function removeEmptyAttributes($attributes, $strip_empty_array = TRUE) {
  foreach ($attributes as $key => $value) {
    if (is_array($value)) {

      // Remove empty values.
      foreach ($value as $k => $v) {
        if (empty($v)) {
          unset($attributes[$key][$k]);
        }
      }

      // Remove the 'count' property.
      unset($value['count']);
      unset($attributes[$key]['count']);

      // Remove attributes with no values.
      if ($strip_empty_array && count($attributes[$key]) == 0) {
        unset($attributes[$key]);
      }
    }
  }
  return $attributes;
}