在字符串中包含常量而不进行串联 [英] Include constant in string without concatenating

查看:106
本文介绍了在字符串中包含常量而不进行串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中有没有一种方法可以在字符串中包含常量而不进行串联?

define('MY_CONSTANT', 42);

echo "This is my constant: MY_CONSTANT";

解决方案

否.

使用字符串,除了常量标识符外,PHP无法分辨字符串数据.这适用于PHP中的任何字符串格式,包括heredoc.

constant() 是另一种方法来获取常量,但是在没有连接的情况下也无法将函数调用放入字符串中.

有关PHP中常量的手册

Is there a way in PHP to include a constant in a string without concatenating?

define('MY_CONSTANT', 42);

echo "This is my constant: MY_CONSTANT";

解决方案

No.

With Strings, there is no way for PHP to tell string data apart from constant identifiers. This goes for any of the string formats in PHP, including heredoc.

constant() is an alternative way to get hold of a constant, but a function call can't be put into a string without concatenation either.

Manual on constants in PHP

这篇关于在字符串中包含常量而不进行串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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