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

在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!

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能