doujiyong7604
2017-08-07 09:13
浏览 25
已采纳

在php中过滤数组中的特定列

I am trying to filter a specific column in an array in php using the code below:

(strpos( 'meeting',$event['categories'] ) == false )

It is not working actually. An example of what [categories] hold is:

$event['categories'] = 'meeting;skype'

Thanks in advance!

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用以下代码过滤php中数组中的特定列:

 (strpos('meeting',$ event ['categories'])== false)
   
 
 

它实际上无法正常工作。 [categories]所持有的一个例子是:

$ event ['categories'] ='meeting; skype' < p>提前致谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongtao9887 2017-08-07 09:26
    已采纳

    You need to flip the arguments to strpos():

    if (strpos($event['categories'],  'meeting') === false) {
        echo $event['categories'] . ' does not contain "meeting"';
    }
    

    Also, use strict comparison (=== vs ==), as meeting could be at the start of the string, and then strpos() would return 0, which would evaluate to false (which would be wrong in that case).

    For reference, see:

    For an example, see:

    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题