Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why check $_GET twice?

Tags:

php

get

isset

I'm learning PHP and I hoping you can explain why the author of a shopping cart tutorial has done this in a call to add a product to a cart.

if(isset($_GET['action']) && $_GET['action']=="add")

The site checks that $_GET[action] is set and that $_GET[action] is equal to 'add' before processing but isn't this functionally equivalent to just:

if($_GET['action']=="add")

Because if the value is 'add' it has to be set, and if it's not set it can't possibly be 'add' right? Or am I missing something?

like image 959
AzzaClazza Avatar asked Dec 24 '22 15:12

AzzaClazza


1 Answers

No, thats not the same Let me explaint 1. isset check either key is set in array 2. Double equals check the simple comparison

like image 50
Sunny Mahajan Avatar answered Dec 27 '22 19:12

Sunny Mahajan