教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP使用动态 Constant与Define值

PHP使用动态 Constant与Define值

发布时间:2016-10-26   编辑:jiaochengji.com
教程集为您提供PHP使用动态 Constant与Define值等资源,欢迎您收藏本站,我们将为您提供最新的PHP使用动态 Constant与Define值资源
在php中Constant与Define是常量那么下面我介绍一个方法能实现动态来使用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 的值, 范例如下:

<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('copy9500')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9500>

<?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变量的区别

[关闭]
~ ~