s_p
s_p

Reputation: 4693

php send value of 0 using $_GET variable

How can i pass a $_GET variable value of '0' while checking if it exists? For example I normally check to see is the variable exists by:
$myVar= (!isset($_GET['t1'])? $_GET['t1'] : '');
or
$myVar= (!empty($_GET['t1'])? $_GET['t1'] : '');

but either both of these checks return false

Upvotes: 0

Views: 225

Answers (1)

Patrick Moore
Patrick Moore

Reputation: 13344

Your first line isn't doing what you expect, because it's asking: is $_GET['t1'] not set? If it's not, $myvar = $_GET['t1']. If it is set, $myvar = ''.

$myVar= (!isset($_GET['t1'])? $_GET['t1'] : '');

So it should be:

$myVar= (isset($_GET['t1'])? $_GET['t1'] : '');

Upvotes: 3

Related Questions