I have the following function.
I can run it to test if true, or else false or vice versa as shown.
$fname=$_POST['fname'];
$lname=$_POST['lname'];
function namecheck ($fname,$lname)
{
$names= array ($fname,$lname);
$regexp ="/^[A-Za-z]+$/";
//filter through names
for ($i=0; $i<2; $i++)
if (! preg_match($regexp, $names[$i]))
{
return false;
}
return true;
}
(Alternate Version):
for ($i=0; $i<2; $i++)
if (preg_match($regexp, $names[$i]))
{
return true;
}
return false;
Which is the better way to write this, both in terms of efficiency and good coding practices? Or is there no difference?
It may not be an issue for a small array like this, but I am wondering what effect it would have on a larger and more complex program.