有没有更好的解决方案来检查许多变量以查看其中之一在PHP中是否为null?

一个PHP文件中,$_REQUEST []或$_POST []接收到许多变量,如果函数isset()的值为空,我必须检查它们,这很麻烦.有更好的解决方案吗?

解决方法:

如何结合使用in_arrayarray_map,例如:

// array of possible parameters that can be passed by the client
$keys = array('username','password');

// this will store the names of the ones that are not present
$missing = array();

foreach($keys as $key) {
    if(!in_array($key, $_POST)) {
        $missing[] = $key;
    }
}

$nullOffsets = array_map("is_null", $_POST);

echo 'Printing missing params:<br />';
print_r($missing);
echo 'Printing null existing params:<br />';
print_r($nullOffsets);

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...