Flatten array with exceptions.

@param array $array
@return array
971829
public function flatten(array $array)
    {
        $return = [];
        foreach ($array as $key => $value) {
            if (in_array($key, $this->exceptions)) {
                $return[$key] = $value;
            } else {
                $return[] = $value;
            }
        }

        return $return;
    }
1059742
public function toMappedArray(array $array)
    {
        $mappedArray = [];
        foreach ($this->getMapper() as $from => $to) {
            $mappedArray[$to] = $array[$from];
        }
        return $mappedArray;
    }
1235366
public static function flatten($array)
    {
        if (!is_array($array)) {
            // nothing to do if it's not an array
            return array($array);
        }

        $result = array();
        foreach ($array as $value) {
            // explode the sub-array, and add the parts
            $result = array_merge($result, static::flatten($value));
        }

        return $result;
    }
910332
private function flatten(array $array)
    {
        $single = array();
        if (isset($array['hier'])) {
            unset($array['hier']);
        }
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                foreach ($this->flatten($value) as $key => $value) {
                    $single[$key] = $value;
                }
            } else {
                $single[$key] = $value;
            }
        }

        return $single;
    }
549461
public static function cleanBeforeJson(array $array): array
    {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $array[$key] = self::cleanBeforeJson($array[$key]);
            }

            if ($array[$key] === '' || null === $array[$key]) {
                unset($array[$key]);
            }
        }

        return $array;
    }
813774
public static function flatten($array, $preserveKeys = true, &$out = array())
    {
        array_walk_recursive(
            $array,
            function ($value, $key) use (&$out, $preserveKeys) {
                if (!is_scalar($value)) {
                    // Do nothing
                } elseif ($preserveKeys) {
                    $out[$key] = $value;
                } else {
                    $out[] = $value;
                }
            }
        );

        return $out;
    }
952847
public function stdClassToArrayCheckValues(array $array)
    {
        foreach ($array as $key => $value) {
            if ($value instanceof \stdClass) {
                $array[ $key ] = $this->stdClassToArray($value);
            } else if (is_array($value)) {
                $array[ $key ] = $this->stdClassToArrayCheckValues($value);
            } else {
                $array[ $key ] = $value;
            }
        }

        return $array;
    }
62579
private
    static function objectify(
        array $array
    ) {
        foreach ($array as &$item) {
            if (is_array($item)) {
                $item = self::objectify($item);
            }
        }

        return (object)$array;
    }
1214976
public static function flattenArray(array $array, $separator = '_')
    {
        $resultArray = [];
        foreach ($array as $key => $val) {
            if (is_array($val)) {
                /* @noinspection AdditionOperationOnArraysInspection */
                $resultArray += self::prefixArray(self::flattenArray($val), $key, $separator);
            } else {
                $resultArray[$key] = $val;
            }
        }

        return $resultArray;
    }
368932
public static function toUnderscore(array $array = [])
    {
        $output = [];
        foreach ($array as $key => $value) {
            $key = StringUtils::toUnderscore($key);
            if (is_array($value)) {
                $value = static::toUnderscore($value);
            }
            $output[$key] = $value;
        }

        return $output;
    }
942443
private function NormalizeArray($Array) {
      $Return = array();
      foreach ($Array as $Key => $Value) {
         if (is_array($Value) === TRUE && array_key_exists(0, $Value) === FALSE) {
            foreach($Value as $k => $v) {
               $Return[$Key.'.'.$k] = $v;
            }
         } else {
            $Return[$Key] = $Value;
         }
      }
      return $Return;
   }
1250118
public static function flattenAssoc(array $array, $depth = INF) : array
    {
        $result = [];
        $depth = is_int($depth) ? max($depth, 0) : INF;

        foreach ($array as $key => $value) {
            if (is_array($value) && $depth >= 1) {
                $result = self::flattenAssoc($value, $depth - 1) + $result;
            } else {
                $result[$key] = $value;
            }
        }

        return $result;
    }
63663
public static function array_flatten_multidim($array, $prefix = false)
    {
        $return = array();
        if (is_array($array) || is_object($array)) {
            if (empty($array)) {
                $return[$prefix] = '';
            } else {
                foreach ($array as $key => $value) {
                    if (is_scalar($value)) {
                        if ($prefix) {
                            $return[$prefix . '[' . $key . ']'] = $value;
                        } else {
                            $return[$key] = $value;
                        }
                    } else {
                        if ($value instanceof \CURLFile) {
                            $return[$key] = $value;
                        } else {
                            $return = array_merge(
                                $return, self::array_flatten_multidim(
                                    $value, $prefix ? $prefix . '[' . $key . ']' : $key));
                        }
                    }
                }
            }
        } elseif ($array === null) {
            $return[$prefix] = $array;
        }
        return $return;
    }
1137119
public static function createFromArray(array $array): self
    {
        $aggregations = new self(
            $array['total_elements'] ?? 0
        );

        if (isset($array['aggregations'])) {
            foreach ($array['aggregations'] as $aggregationName => $aggregation) {
                $aggregations->addAggregation(
                    $aggregationName,
                    Aggregation::createFromArray($aggregation)
                );
            }
        }

        return $aggregations;
    }
1033343
private function arrayFilterRecursive(array &$array)
    {
        foreach ($array as $key => &$item) {
            is_array($item) && $array[$key] = $this->arrayFilterRecursive($item);
            if ($array[$key] === null ||
                $array[$key] === []
            ) {
                unset($array[$key]);
            }
        }
        return $array;
    }
1332324
public static function mergeSort($array): array
    {
        if (count($array) === 1) {
            return $array;
        }

        $middle = (int)round(count($array) / 2);
        $left = array_slice($array, 0, $middle);
        $right = array_slice($array, $middle);

        $left = self::mergeSort($left);
        $right = self::mergeSort($right);

        return self::merge($left, $right);
    }
1272438
public static function flattenArray(array $array, $prefix = '')
    {
        $prefix = self::keySanitize($prefix);
        $result = [];
        foreach ($array as $key => $val) {
            $key = strtolower($key);
            if (is_array($val)) {
                $result += self::flattenArray($val, $prefix.$key.'.');
                continue;
            }
            $key = self::keySanitize($key);
            $newKey = rtrim($prefix.$key, '.');
            $result[$newKey] = $val;
        }
        return $result;
    }