checking if condition for 0 value
in if condition i want to check
if(isset($_GET['q']))
{
echo "ok";
}
esle
{
echo "not ok";
}
when $_GET['q']=0 if send me in else part.
But i want t开发者_如何学编程o go in if .
if $_GET['q'] have any value even for 0 if should print ok
any help pls ?
This is what isset
does. Try:
$x["q"] = 0;
var_dump(isset($x["q"]));
You will get true. If you think isset()
returns false
on 0
you are looking at the wrong place, look for a bug elsewhere.
0 is not null http://php.net/manual/en/function.isset.php
You might need something like this considering the value you want is integer
if(isset($_GET['q']) && intval($_GET['q']) > 0 )
{
echo "ok";
}
else
{
echo "not ok";
}
perhaps array_key_exists()
would be more appropriate.
if ( array_key_exists( 'q', $_GET ) ) ...
I think this is the correct one...
if(array_key_exists('q', $_GET)){
echo "ok";
}
else{
echo "not ok";
}
精彩评论