You are here

private static function Braintree_Util::_flattenArray in Commerce Braintree 7

flattens a numerically indexed nested array to a single level

Parameters

array $keys:

string $namespace:

Return value

array

1 call to Braintree_Util::_flattenArray()
Braintree_Util::verifyKeys in braintree_php/lib/Braintree/Util.php
verify user request structure

File

braintree_php/lib/Braintree/Util.php, line 210

Class

Braintree_Util
Braintree Utility methods

Code

private static function _flattenArray($keys, $namespace = null) {
  $flattenedArray = array();
  foreach ($keys as $key) {
    if (is_array($key)) {
      $theKeys = array_keys($key);
      $theValues = array_values($key);
      $scope = $theKeys[0];
      $fullKey = empty($namespace) ? $scope : $namespace . '[' . $scope . ']';
      $flattenedArray = array_merge($flattenedArray, self::_flattenArray($theValues[0], $fullKey));
    }
    else {
      $fullKey = empty($namespace) ? $key : $namespace . '[' . $key . ']';
      $flattenedArray[] = $fullKey;
    }
  }
  sort($flattenedArray);
  return $flattenedArray;
}