- array_map: documentation ( source)
- preg_match: documentation ( source)
- implode: documentation ( source)
<?php
$recipients = ["kumar","ram@test.com","ravi","rob@example.com"];
$pattern = "/^[^\s@]+@[^\s@]+\.[^\s@]+$/";
$s = implode(
", ",
array_map(fn($user) => preg_match($pattern, $user) ? $user : $user . "@test.com", $recipients)
);
echo $s;