tags:

views:

129

answers:

2

if (strlen($title) && strlen($message) > 3)

This returns true if $title is over 3 chars, I only want it to return true if BOTH is. Whats the correct way? Tried a bunch. FNYS.

Help please.

+9  A: 

if ((strlen($title) > 3) && (strlen($message) > 3))

I do see what you're shooting for, but it's not often supported. In general, each chunk of the "if" test is self-standing -- I like to add extra parentheses, just to make things clearer to scan.

So your original test boiled down to "if(strlen($title))" and "if(strlen($message) > 3)".

DreadPirateShawn
Clear and straight forward. I like it.
Abinadi
Iagree...with the neatness of the solution
Learner
+5  A: 

if (min(strlen($title), strlen($message)) > 3)

treznik