我的if else语句怎么了 [英] Whats wrong with my if else statement

查看:78
本文介绍了我的if else语句怎么了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含字符串的$name变量,当我对其进行测试时,即使长度少于2个字符或大于40个字符,也从未收到名称应介于2到40个字符之间"的错误.为什么?

I have a $name variable containing a string, and when I test it, I never get the "Name should be between 2 and 40 characters" error even when it's less than 2 characters long or more than 40. Why?

if (strlen($name) < 2 && strlen($name) > 40) {
    $nameError = 'Name should be between 2 and 40 characters';
}

推荐答案

长度如何小于2 大于40?您需要||(或"),而不是&&(和").

How can the length be less than 2 and greater than 40? You want || ("or"), not && ("and").

if (strlen($name) < 2 || strlen($name) > 40) {
// -------------------^^

这篇关于我的if else语句怎么了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆