php递归判断数组值不能为空


    /**
     * 验证数组值 不能为空 ''
     * @param  [array] $data [请求数据]
     * @param  [array] $not_check [跳过检验]
     * @return [array]       [返回未通过的key]
     */
    public static function checkArrayValue($data, $not_check = [])
    {
        $record = array('success' => true, 'paramName' => '');
        if (empty($data)) {
            $record = array('success' => false, 'paramName' => '');
            return $record;
        }
        // 判断参数值是否为空
        foreach ($data as $d_key => $d_val)
        {
            if ((!in_array($d_key, $not_check)) && ((empty($d_val) && (!in_array($d_val, [0, '0'], true))) || (is_numeric($d_val) && (intval($d_val) < 0)))) {
                $record = array('success' => false, 'paramName' => $d_key);
                return $record;
            }
            // 如果是数组 继续调用自身
            if ((!in_array($d_key, $not_check, true)) && is_array($d_val))
            {
                $record1 = self::checkArrayValue($d_val, $not_check);
                if (empty($record1['success']))
                {
                    return $record1;
                }
            }
        }
        return $record;
    }
发布了50 篇原创文章 · 获赞 8 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_36999656/article/details/100096771

相关文章