public function SimpleLdap::removeEmptyAttributes in Simple LDAP 8
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.
File
- src/
SimpleLdap.php, line 74
Class
- SimpleLdap
- A wrapper for PHP's LDAP functions, with associated helper methods.
Namespace
Drupal\simple_ldapCode
public 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;
}