douwen3127 2014-05-26 06:22
浏览 40
已采纳

如何在PHP中缩短多个isset函数

Look at my script:

if((isset($_POST['unma']) && isset($_POST['livi'])) && (isset($_POST['cont']) && 

    isset($_POST['phone']))){
        if(
            (
                (
                    (
                        (isset($_POST['fnma']) && isset($_POST['lnma']))
                        &&
                        (isset($_POST['occ']) && isset($_POST['hom']))
                    )
                    &&
                    (
                        (isset($_POST['town']) && isset($_POST['dist']))
                        &&
                        (isset($_POST['dispmb']) && isset($_POST['fbc']))
                    )
                )
                &&
                (
                    (
                        (isset($_POST['gp']) && isset($_POST['twt']))
                        &&
                        (isset($_POST['ins']) && isset($_POST['flc']))
                    )
                    &&
                    (
                        (isset($_POST['ile']) && isset($_POST['cam']))
                        &&
                        (isset($_POST['cam_co']) && isset($_POST['prof_phr']))
                    )
                )
            )
            &&
            isset($_POST['awards'])
        ){
                // Codes here
        }

How can I short this isset functions. I found an solution with foreach but they are not checking the post isset, rather they are checking if the posted values are not empty

  • 写回答

5条回答 默认 最新

  • dttwois6098 2014-05-26 06:29
    关注

    You can use

    if (isset($_POST['a'], $_POST['b'], $_POST['c'], ...))
    

    and so on. If any of the variables is not set then you will get false.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败