You are here

function _features_sanitize in Features 7.2

Same name and namespace in other branches
  1. 6 \_features_sanitize()
  2. 7 \_features_sanitize()

Internal. "Sanitizes" a (nested) array (or object) recursively.

The following operations are performed on every recursion level:

  • Objects are converted to array via get_object_vars().
  • "Associative" arrays are sorted by key.
  • Non-associative/serial arrays are sorted by value.
  • Empty values and empty sub-trees are removed if $remove_empty is TRUE.

@internal This function is designed for internal use within @todo Needs unit tests. @todo A better name might be "normalize", not "sanitize".


array|object|mixed $array: Array or object to be sanitized. If $array is an object, it will be converted to array via get_object_vars(). Any nested objects will be converted to array in the same way. If $array is not an array or object, it will be left as-is.

bool $remove_empty: If TRUE, remove null or empty values for assoc arrays. This will also remove empty arrays or objects nested in the hierarchy.

See also


1 call to _features_sanitize()
features_sanitize in ./
Helper function to "sanitize" an array or object.


./, line 1513
Contains functions that export configuration into feature modules.


function _features_sanitize(&$array, $remove_empty = TRUE) {
  if (is_object($array)) {
    $array = get_object_vars($array);
  if (is_array($array)) {
    $is_assoc = _features_is_assoc($array);
    if ($is_assoc) {
      ksort($array, SORT_STRING);
      if ($remove_empty) {
        $array = array_filter($array);
    else {
    foreach ($array as $k => $v) {
      if (is_array($v) or is_object($v)) {
        if ($remove_empty && $is_assoc && empty($array[$k])) {