引用php中的常量:“这是MY_CONSTANT"; [英] quoting constants in php: "this is a MY_CONSTANT"

查看:86
本文介绍了引用php中的常量:“这是MY_CONSTANT";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PHP中使用常量,但我也想像变量一样将其放在双引号中.这有可能吗?

I want to use a constant in PHP, but I also want to put it inside double quotes like a variable. Is this at all possible?

define("TESTER", "World!");
echo "Hello, TESTER";

显然会输出"Hello,TESTER",但是我真正想要的是这样的东西:

obviously outputs "Hello, TESTER", but what I really want is something like:

$tester = "World!";
echo "Hello, $tester";

输出你好,世界!".

推荐答案

对不起,这不是PHP中常量的工作方式.您可以将变量放在双引号和heredocs中,但不能放在常量中.

Sorry, that's not the way constants in PHP work. You can put variables in double quotes and heredocs but not constants.

这篇关于引用php中的常量:“这是MY_CONSTANT";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆