PHP使用动态 Constant与Define值
在php中Constant与Define是常量那么下面我介绍一个方法能实现动态来使用Constant与Define值方法,希望对各位同学有所帮助。
PHP 要秀出 或 使用 动态 Constant / Define 值, 要如何使用呢? ex: 下述范例是动态变数, 但是动态 Constant 要如何使用?
<?php $a = 'abc'; $b = 'a'; echo $$b; // 印出 abc ?>
PHP 使用 动态 Constant / Define 值
可以使用 constant() 来达成使用 Constant 的值, 范例如下:
<?php define('PKEY1', 'abc'); define('PKEY2', 'def'); $i = 1; $a = 'PKEY'; echo constant($a . $i); // abc echo constant($a . ++$i); // def ?>
文章链接:http://www.phprm.com/code/53265.html
随便收藏,请保留本文地址!