duanjue7508 2015-10-22 15:49
浏览 748
已采纳

如何使switch语句不区分大小写?

In the following example, sometimes $var can be "Value", "value" or even "VALUE".

switch ( $var ) {
    case "value":
        // Value and VALUE don't seem to match here.
        break;
}

The comparison seems to be case sensitive (only the all-lowercase "value" matches). Is there a way to perform a case-insensitive comparison?

Ref: http://php.net/manual/en/control-structures.switch.php

  • 写回答

2条回答 默认 最新

  • dtueufe82643 2015-10-22 15:51
    关注
    $var = strtolower($var)
    

    And then in the switch cases write all lowercase

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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