Regarding the problem of judging array parameters in Php
Jason
Jason 2019-06-11 19:04:03
0
4
967
$info =  $this->request->post();//传入的json是个数组。
if(empty($info['企业名称']) || empty($info['企业简称']) || empty($info['纳税人识别号']) || empty($info['企业法人代表']) || empty($info['联系人']) || empty($info['联系人邮箱']) || empty($info['企业电话']) || empty($info['联系人手机']) || empty($info['银行名称']) || empty($info['银行账号']) || empty($info['详细地址']) || empty($info['地区编码']) || empty($info['城市名称']) || empty($info['营业执照照片']) || empty($info['token'])){
    return json_encode(['code'=>2,'msg'=>'所有信息必须填写不能为空!','data'=>[]]);

There is a piece of code like this. Simply put, it is to determine whether there are these Info fields. They cannot be less or empty. Is there any better way to write it?

Jason
Jason

reply all(2)
!

Yes, you can write them separately

  • reply How to write separately
    Jason author 2020-05-28 13:27:58
殘留の回憶

Writing like this is too poor in maintainability and efficiency, just take it apart and write

  • reply How to write it apart
    Jason author 2019-06-16 21:54:30
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!