douhao6271 2014-11-05 07:28
浏览 33
已采纳

为什么$ string [0] =''不会导致$ string [0] ===''?

$s = 'abc';
$s[0] = '';
if ($s[0] !== '') {
    echo 'emmm';
}

Why $string[0] = '' is not resulting $string[0] === ''?

seems like $string[0] === "\0", but more confusing..

  • 写回答

4条回答 默认 最新

  • dongye9191 2014-11-05 08:00
    关注

    $s[0] gives access to a single character of the string. '' is not a character, it's a string, so the assignment fails. You get the exact same behavior if you try to assign FALSE to $s[0]. It looks like PHP does its best to convert whatever value you assign into a single character. If you assign a non-empty string, it will use the first character. If you assign a number, it will use the first digit. If you assign the value TRUE, it will use 1.

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

报告相同问题?

悬赏问题

  • ¥15 vc6.0中想运行代码的时候总是提示无法打开文件是怎么回事
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题