0

What is wrong with this if-else statement.

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. My test string is 11 char, and I am seeing string to short/to long. 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)

3 Answers 3

2
if (strlen($objectData['pss']) >= 8 && strlen($objectData['pss']) <= 20)
Sign up to request clarification or add additional context in comments.

1 Comment

hah. I see what I did wrong between yours and mine.. wow, guess I am just that tired, thank you :-)
0
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

Comments

0

Yes you are indeed "to tired".. You are basically counting the length of an expression instead of the string itself:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.