Perforce Chronicle 2012.2/486814
API Documentation
|
Flattens a multi-dimensional array using array notation for the keys to represent the hierarchy. More...
Public Member Functions | |
filter ($input) | |
Flatten multi-dimensional input array using array notation. | |
Protected Member Functions | |
_flatten ($input, $prefix, array &$output=array()) | |
Recursively flatten the given input array. |
Flattens a multi-dimensional array using array notation for the keys to represent the hierarchy.
P4Cms_Filter_FlattenArray::_flatten | ( | $ | input, |
$ | prefix, | ||
array &$ | output = array() |
||
) | [protected] |
Recursively flatten the given input array.
mixed | $input | a input variable to flatten. |
string | $prefix | the key prefix to use. |
array | &$output | the flattened output array (by reference). |
{ if (!is_array($input)) { $output[$prefix] = $input; return; } foreach ($input as $key => $value) { $key = $prefix . "[" . $key . "]"; if (is_array($value)) { $this->_flatten($value, $key, $output); } else { $output[$key] = $value; } } }
P4Cms_Filter_FlattenArray::filter | ( | $ | input | ) |
Flatten multi-dimensional input array using array notation.
array | $input | the multi-dimensional input array to flatten. |
{ // only flatten arrays. if (!is_array($input)) { throw new InvalidArgumentException("Cannot flatten. Value is not an array."); } $output = array(); foreach ($input as $key => $value) { $this->_flatten($value, $key, $output); } return $output; }