Avatar ·

Replacing array keys based on another lookup/mapping array

Hello colleagues! I'm new to PHP and faced with a task that seems simple, but I can't find an elegant solution.\n\nI have a source associative array with user data, for example:\n\n```php\n$userData = [\n 'user_id' => 42,\n 'first_name' => 'Ivan',\n 'last_name' => 'Petrov',\n 'email_address' => 'ivan@example.com',\n 'phone_number' => '+7-999-123-45-67',\n 'registration_date' => '2023-05-15'\n];\n```\n\nAnd there is a second array that defines how to rename the keys (mapping old keys to new ones):\n\n```php\n$keyMapping = [\n 'user_id' => 'id',\n 'first_name' => 'name',\n 'last_name' => 'surname',\n 'email_address' => 'email',\n 'phone_number' => 'phone',\n 'registration_date' => 'registered_at'\n];\n```\n\nI need to