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 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥15 抖音看过的视频,缓存在哪个文件