在PHP中将字符串转换为定义的常量 [英] Converting a string to a defined constant in PHP
本文介绍了在PHP中将字符串转换为定义的常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
比方说,我已经定义了常量 ERROR_0
如下:
Let's say my I have defined the constant ERROR_0
as follows:
define("ERROR_0","An error occurred.")
现在,假设我有字符串 ERROR_0,但我想将其转换为常量 ERROR_0
,这样我就可以获取字符串发生错误。我该怎么办?
Now, let's say I have the string "ERROR_0" but I want to convert that into the constant ERROR_0
such that I can get the string "An Error occurred." How can I do that?
谢谢!
推荐答案
使用< href = http://php.net/manual/zh/function.constant.php rel = noreferrer> constant
函数
echo constant("ERROR_0");
这篇关于在PHP中将字符串转换为定义的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文