php中if..else语句中的多个逻辑运算符

firstname and lastname are being submitted from a HTML form.

In PHP i want to check that both of them must be atleast 3 characters long and maximum upto 18 characters. How can i check it in an if else statement

Example code is below

$f = $_POST['firstname'];
$l = $_POST['lastname'];
if((strlen($f) < 3 || strlen($f) > 16) && (strlen($l) < 3 || strlen($l) > 16))
{
    echo "Firstname and lastname must be between 3 and 16 characters";
    exit();
}

It is not working what i have done wrong.....

Thanks for help and I hope you understand my problem

if((strlen($f) < 3 || strlen($f) > 16) || (strlen($l) < 3 || strlen($l) > 16))

Replace && in the middle by ||

What you did only throws the error when both aren't valid. You want to throw it when one of them is.

try this..

if((strlen($f) <= 3 && strlen($f) >= 18 ) && (strlen($l) <= 3 && strlen($l) >= 18 ))
{
echo "Firstname and lastname must be between 3 and 16 characters";
}
else
{
//query here..
}