Page 1 of 1

difference in these queries

Posted: Thu Oct 13, 2011 5:45 pm
by jonathon
Hi,
I was just wondering what is the difference between these 2 queries (if any)
if(isset($_GET['a']) && (strlen($_GET['a'])) == 32 && (ctype_alnum($_GET['a']))) {

//****** AND ********//

if(isset($_GET['a']) && strlen($_GET['a']) == 32 && ctype_alnum($_GET['a'])) {

I normally use the bottom kind but was just playing with some code and noticed it was still valid with the brackets around each condition too. Do they differ at all in execution?

Re: difference in these queries

Posted: Thu Oct 13, 2011 6:11 pm
by libeco
In this case there's no difference since every condition has to evaluate to TRUE. If you want to make more complex check you need to extra ( and ) to separate different parts of a statement. You can also use it to make it more readable for yourself:
if ((2 == 2 || 3 == 3) && (4 == 4 || 5 == 5)) {

Re: difference in these queries

Posted: Thu Oct 13, 2011 7:02 pm
by jonathon
Thanks Libeco