如何检查索引是否存在而在php中不为null

Hab*_*wad 3 php null isset

我总是使用以下代码来检查索引是否存在且不是null:

if(!(isset($_POST['service']) and $_POST['service']))
   die('The service parameter is not available.');
Run Code Online (Sandbox Code Playgroud)

我在这里检查两个条件.是否可以使用单个buit-in功能来完成?例如:-

if(!isSetAndNotNull($_POST['service']))
   die('The service parameter is not available.');
Run Code Online (Sandbox Code Playgroud)

Naj*_*ero 6

你应该使用empty().

http://php.net/manual/en/function.empty.php

为空(false)或空(null)返回false