7 private array $processedKeys = [];
11 $this->processedKeys = $processedKeys;
14 public function flatten(array $input): array
16 if (!empty($this->processedKeys))
18 return $this->flattenWithCheckKeys($input);
21 foreach ($input as $key => $value)
25 $newItems = $this->getFlattenFields($value, $key);
26 foreach ($newItems as $newKey => $newValue)
28 $input[$newKey] = $newValue;
36 private function flattenWithCheckKeys(array $input): array
38 foreach ($input as $key => $value)
40 if (is_array($value) && in_array($key, $this->processedKeys,
true))
42 $newItems = $this->getFlattenFields($value, $key);
43 foreach ($newItems as $newKey => $newValue)
45 $input[$newKey] = $newValue;
53 private function getFlattenFields(array $fields,
string $prefix): array
57 foreach ($fields as $name => $value)
59 $key =
"{$prefix}[{$name}]";
62 array_push($result, ...$this->getFlattenFields($value, $key));
66 $result[$key] = $value;