search

Home  >  Q&A  >  body text

Regarding the problem of judging array parameters in Php

$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?

JasonJason2041 days ago1052

reply all(4)I'll reply

  • WJ

    WJ2020-05-27 13:57:57

    Yes, you can write them separately

    reply
    0
  • Jason

    How to write separately

    Jason · 2020-05-28 13:27:58
  • 殘留の回憶

    殘留の回憶2019-06-16 21:53:16

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

    reply
    0
  • Jason

    How to write it apart

    Jason · 2019-06-16 21:54:30
  • Cancelreply