difference in these queries

Ask about a PHP problem here.
Post Reply
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

difference in these queries

Post 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?
libeco
Posts: 104
Joined: Sat May 07, 2011 9:56 am

Re: difference in these queries

Post 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)) {
jonathon
Posts: 50
Joined: Fri May 06, 2011 5:09 pm

Re: difference in these queries

Post by jonathon »

Thanks Libeco
Post Reply