<?php function print_line(string $output): void { echo $output . PHP_EOL; } function normalize_property_keys(array $props, ?array $matchers = []): array { $normalized = []; foreach ($props as $key => $value) { $matched_key = $matchers[$key] ?? null; if ($matched_key) { $normalized[$matched_key] = $value; } else { $norm_key = preg_replace('/[-\s]+/', '', $key); $normalized[$norm_key] = $value; } } return $normalized; } $keys = [ 'align' => 'alignment', 'col' => 'color', 'colour' => 'color', ]; $tests = [ 'align' => 1, 'col' => 2, 'test-key' => 3, 'test_new_key' => 4, ]; print_line("Original Array"); print_r($tests); print_line(""); print_line("Normalized Array"); print_r(normalize_property_keys($tests, $keys));
You have javascript disabled. You will not be able to edit any code.