$namesPartsArrays = [ $firstname, $lastname ];
$namesCount = 5;
$rand = fn($arr) => array_map(fn($n) => $arr[$n], array_rand($arr, $namesCount));
$namesParts = array_map($rand, $namesPartsArrays);
$names = implode(', ', array_map(fn(...$parts) => implode(' ', $parts), ...$namesParts)).'.';