private static function expandArrays($deserialized) { $dataWithExpandedArrays = []; foreach ($deserialized as $key => $value) { if (is_array($value)) { $value = self::expandArrays($value); } // https://regex101.com/r/bA6uD2/3 if (preg_match("/(.*)\\[([^]]+)\\]\$/", $key, $matches)) { $originalKey = $matches[1]; $subkey = $matches[2]; $dataWithExpandedArrays[$originalKey][$subkey] = $value; } else { $dataWithExpandedArrays[$key] = $value; } } return $dataWithExpandedArrays; }