You are here

function _array_flatten in Panels Content Cache 7

A copy of options_array_flatten() that doesn't rely on the Options module, adjusted to properly handle objects and avoid collisions in nested arrays.

Parameters

array @array: The array to be flattened.

string $namespace: Optional prefix used to avoid array elements being overridden, thus avoid collisions.

Return value

array The argument flattened into a single level.

1 call to _array_flatten()
panels_content_cache_get_cid in plugins/cache/content.inc
Figure out a cache id for our cache based upon input and settings.

File

plugins/cache/content.inc, line 430
Provides a content-based caching option for panel panes.

Code

function _array_flatten($array, $namespace = NULL) {

  // Each dimension of an array will be prefixed by the parent's value.
  if (isset($namespace)) {
    $namespace .= '_';
  }
  $result = array();
  if (is_array($array)) {
    foreach ($array as $key => $value) {
      if (is_array($value) || is_object($value)) {
        $result += _array_flatten((array) $value, $namespace . $key);
      }
      else {
        $result[$namespace . $key] = $value;
      }
    }
  }
  return $result;
}