Reputation: 7048
I am always using the following code to check if an index exists and is not null:
if(!(isset($_POST['service']) and $_POST['service']))
die('The service parameter is not available.');
Here I am checking two conditions. Is it possible to do it using a single buit-in function? eg:-
if(!isSetAndNotNull($_POST['service']))
die('The service parameter is not available.');
Upvotes: 3
Views: 742
Reputation: 41605
Rather than empty
I would use !
:
if(!$_POST['service'])
die('The service parameter is not available.');
In case of using it with functions it avoid troubles.
Explanation here: https://stackoverflow.com/a/4328049/1081396
Upvotes: 1
Reputation: 3212
You should use empty() for that.
http://php.net/manual/en/function.empty.php
returns false for empty(false) or empty(null)
Upvotes: 6