PHP使用动态 Constant与Define值
PHP 要秀出 或 使用 动态 Constant / Define 值, 要如何使用呢? ex: 下述范例是动态变数, 但是动态 Constant 要如何使用?
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1113')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1113>
<?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
?>
您可能感兴趣的文章:
PHP使用动态 Constant与Define值
php常量 定义与使用php常量
深入分析PHP const与define使用区别
深入分析php中const和define定义常量的区别
PHP5.6 CONST新特性几个例子
详解PHP中const和define的区别
php常量定义的方式有哪些
php 定义常量define()与普通变量
PHP变量详解和定义变量名的方法
php中static const define变量的区别