一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

PHP使用动态 Constant与Define值

时间:2013-10-22 编辑:简简单单 来源:一聚教程网

PHP 要秀出 或 使用 动态 Constant / Define 值, 要如何使用呢? ex: 下述范例是动态变数, 但是动态 Constant 要如何使用?

 代码如下 复制代码


$a = 'abc';
$b = 'a';
echo $$b; // 印出 abc
?>


PHP 使用 动态 Constant / Define 值
可以使用 constant() 来达成使用 Constant 的值, 范例如下:

 代码如下 复制代码

define('PKEY1', 'abc');
define('PKEY2', 'def');
$i = 1;
$a = 'PKEY';
echo constant($a . $i); // abc
echo constant($a . ++$i); // def
?>

热门栏目