- is_numeric: documentation ( source)
- print_r: documentation ( source)
- str_replace: documentation ( source)
- ucfirst: documentation ( source)
<?php
function formatAds(array $ad): array
{
$ad['last_name'] = ucfirst($ad['last_name']);
$ad['first_name'] = ucfirst($ad['first_name']);
$phoneNumber = str_replace(' ', '', $ad['phone_number']);
$ad['phone_number'] = is_numeric($phoneNumber) && strlen($phoneNumber) === 10 ? $phoneNumber : null;
return $ad;
}
$ad = [
"last_name" => "foo",
"first_name" => "bar",
"phone_number" => "04 55 66 77 11",
];
print_r(formatAds($ad));