PHP校验表单数据是否有空值的另类写法

01-11 16:56 字数 619 阅读 568 已编辑
$resp = ['status' => ERROR_CODE, 'msg' => '', 'data' => ''];

$cnyAmount = Request::post('cnyAmount', '', 'inputFilter');
$cnyUnitPrice = Request::post('cnyUnitPrice', '', 'inputFilter');
$receiptType = Request::post('receiptType', '', 'inputFilter');
$type = Request::post('type', '', 'intval');
// $formData = inputFilter(Request::post());
// extract($formData);
$checkFlag = call_user_func_array(function () {
    $args = func_get_args();
    if (empty($args)) return false;
    foreach ($args as $arg) {
        if ($arg === '') return false;
    }
    return true;
}, [$cnyAmount, $cnyUnitPrice, $receiptType, $type]);
if (!$checkFlag) {
    $resp['msg'] = "请检查表单是否输入完整";
    return $resp;
}

call_user_func_array做数据校验,其实代码量也没少😀

0人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论