Use isset()
in the ternary operator:
$name = isset($_GET["name"]) ? $_GET["name"] : 0;
You get the notice because you evaluate $_GET['name']
directly, without using isset()
or empty()
wrapper.
You might prefer to make a resuble function to simply your code:
function filterThing($key){
return isset($_GET[$key]) ? $_GET[$key] : 0;
}
$name = filterThing('name');
$type = filterThing('type');
$other = filterThing('other');