<?php
function formatAds(array $ad): array
{
$ad['last_name'] = ucfirst($ad['last_name']);
$ad['first_name'] = ucfirst($ad['first_name']);
$phoneNumber = preg_replace(['/ /', '/^0?33/'], ['', '0'], $ad['phone_number']);
$ad['phone_number'] = preg_match('/^0[1-9][\d]{8}$/', $phoneNumber, $matches) ? $matches[0] : null;
return $ad;
}
$ad1 = [
"last_name" => "foo",
"first_name" => "bar",
"phone_number" => "04 55 66 77 11",
];
$ad2 = [
"last_name" => "flow",
"first_name" => "blow",
"phone_number" => "334 55 66 77 11",
];
$ad3 = [
"last_name" => "beez",
"first_name" => "wiiz",
"phone_number" => "0334 55 66 77 11",
];
print_r(formatAds($ad1));
print_r(formatAds($ad2));
print_r(formatAds($ad3));
preferences:
25.46 ms | 407 KiB | 5 Q