Reputation: 5025
If I were to create this variable:
$example = $_GET['test'];
I would get this error message if $_GET['test']
is not set:
Notice: Undefined variable...
How can I create variables like this (without having to use if
statements and the like) without having to see this error message?
Upvotes: 0
Views: 70
Reputation: 191789
Typically, I do something like the following:
function get($key, $default = null) {
return isset($_GET[$key]) ? trim($_GET[$key]) : $default;
}
$example = get('test');
Upvotes: 1