dongzouche9108 2012-09-29 01:47
浏览 73
已采纳

PHP - 为什么仍然会解析双精度内的单引号变量

Normally, when variables in PHP are enclosed in single quotes, they are treated as strings, i.e

echo '$variable';

will actually echo the word $variable onto the screen.

So why is it then that this string is parsed:

echo "'$variable'";

That code actually does echo the value of the variable. Why is that? It's still inside single quotes, so why does it still get parsed?

  • 写回答

4条回答 默认 最新

  • douba1214 2012-09-29 01:51
    关注

    Because the single quotes are inside double quotes. Anything inside double quotes gets evaluated. So, your echo statement is passed a string inside double quotes.

    This string is evaluated then output. It contains single quotes and a variable.

    Try this instead:

    <?php
        $var = 10;
        echo '"$var"';
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

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