samedi 16 février 2019

Any way to shorten this if statement? PHP

I'm trying to keep my code nice and elegant. Any way to make this if statement shorter?

if(strlen($cname) > 100) {

} elseif(strlen($cowner) > 100) {

} elseif(strlen($cemail) > 200) {

} elseif(strlen($cpassword) > 100) {

}

I can't do this because I want to print out a specific message for each if statement:

if(strlen($cname) > 100 || strlen($cowner) > 100 || strlen($cemail) > 200 || strlen($cpassword) > 100) {
  // I want to print out a message like email is too long not just one of these strings is too long
}

Aucun commentaire:

Enregistrer un commentaire