douwu3763 2017-10-05 14:45
浏览 59
已采纳

在PHP数组中查找字符串的最佳方法? [重复]

This question already has an answer here:

If I have an array that contains some strings like so

$roleNames = ['sales_agent', 'admin'];

And I want to check if that array contains the string 'sales_agent', what would be the best way to go about this with PHP?

Ideally I would like to have the check return a boolean value.

</div>
  • 写回答

2条回答 默认 最新

  • douzhanjia0773 2017-10-05 14:48
    关注

    Easiest Way

    $word='admin';
    $array = array('sales_agent', 'admin');
    
    if (in_array($word, $array)) {
        echo "admin is in array";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据