I have the following which doesn’t work properly as $_GET['category'] can also equal 0.
if ( empty( $_GET['category'] ) ){
// do something
} else {
// do something else
}
How do I re-write this if statement to do 3 different things
- Do something if
$_GET['category']does not exist at all - Do something if
$_GET['category'] == 0 - Do something if
$_GET['category'] ==something other than “does not exist” and 0.
I’ve tried different combinations of empty(), !empty(), isset(), !isset() but I’m not getting the results I’m after. I’m probably doing the wrong combinations…
This isn’t really hard to do:
issetis the method you need.Note that I have compared for exact equality to the string
'0', becauseGETandPOSTvariables are always strings (or occasionally arrays) and never numbers when PHP first receives them.