So, having an array like the following:
$input = [
'first_name' => 'Alex',
'last_name' => 'UFO',
'email' => '[email protected]',
'phone_number' => '124124',
// .....
'referral_first_name' => 'Jason',
'referral_last_name' => 'McNugget',
'referral_email' => '[email protected]',
'referral_phone_number' => '1212415',
];
After processing the first part, until referral..., do you think of any better way to replace referral_first_name with first_name and so on, then the following? Maybe a more dynamic and automatic way.
$input['first_name'] = $input['referral_first_name'];
unset($input['referral_first_name']);
$input['last_name'] = $input['referral_last_name'];
unset($input['referral_last_name']);
$input['email'] = $input['referral_email'];
unset($input['referral_email']);
$input['phone_number'] = $input['referral_phone_number'];
unset($input['referral_phone_number']);
Guys, I forgot to mention, but I have already done it with foreach, but the problem will be when the array gets pretty large (and usually does, and not by one person using that function, but by many), and that would mean extra unnecessary processing time, since it has to iterate through the whole array, before reaching the referral_.. part.

referral_your keys duplicated and overwitten. Be careful on that. And you can see my answer and working demo