doubingjiu3199 2016-07-19 08:20
浏览 150
已采纳

PHP检查POST方法是否包含其中一个值

can you please help me with a such issue: I need to check, if in array, which is passed in $_POST contains some specific value, and if yes - does some stuff.. currently I have:

$count=count($_POST['prcategory']);
if(implode($_POST['prcategory']) == "'Cost Collection'" && $count=1 ){
  ...do stuff
}
elseif (implode($_POST['prcategory']) == "'Cost Collection'" && $count > 1 )
{
  ...do other stuff
}
else {.... }

But for the unknown for me reason, when the count is >1, it always goes to the last else option - most probably, it's because I'm not aware, how to properly check, if one of POST values contains my needed value ..

Any suggestions on this?

p.s. all values are passed in quotes, e.g. it's fine, that I have quotes in : 'Cost Collection'

  • 写回答

2条回答 默认 最新

  • duancao2082 2016-07-19 08:31
    关注

    use simple if else

    NOTE : $_POST['prcategory'] should be an array() other wise in_array will not work

        if(isset($_POST['prcategory'])) {
         $count = count($_POST['prcategory']);
         $data = $_POST[prcategory];
         if (in_array("'Cost Collection'", $data)) { // 'Cost Collection' is the value to check in array $data u can use any value
                if ($count == 0 ) {
                    //do stuff.......
    
                }elseif($count > 1)  {
                      //do stuff.......
    
                }else {
                    //do stuff.......
                }
    
         }else {
                //do stuff.......
              }
       }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应