简体   繁体   English

php if-else失败

[英]php if-else failing

What is wrong with this if-else statement. 这个if-else语句有什么问题。

if((strlen($objectData['pss'] >= 8))AND(strlen($objectData['pss'] <= 20)))
{
  //do my bidding
}
else
{
  echo "String to short or to long";
}

Ultimately I am trying to find if the variable is greater than or equal to 8 chars while being under or equal to 20 chars. 最终,我试图找出变量是否大于或等于8个字符,同时低于或等于20个字符。 My test string is 11 char, and I am seeing string to short/to long. 我的测试字符串是11个字符,我看到字符串短/长。 I've done similar to this in the past, so I dunno what I mucked up at the moment (maybe Im just to tired to realize it) 我过去做过类似的事情,所以我不知道我现在的情况如何(也许我只是厌倦了才意识到这一点)

if (strlen($objectData['pss']) >= 8 && strlen($objectData['pss']) <= 20)
if ((strlen($objectData['pss']) >= 8) and (strlen($objectData['pss']) <= 20))
{ 
  //do my bidding 
} 
else 
{ 
  echo "String to short or to long"; 
} 

I have corrected you brackets 我纠正了你的括号

是的你确实“累了”..你基本上是在计算表达式的长度而不是字符串本身:

if((strlen($objectData['pss']) >= 8)AND(strlen($objectData['pss']) <= 20))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM