Home > php教程 > php手册 > body text

PHP使用动态Constant与Define值

WBOY
Release: 2016-05-25 16:44:37
Original
1296 people have browsed it

在php中Constant与Define是常量那么下面我介绍一个方法能实现动态来使用Constant与Define值方法,希望对各位同学有所帮助.

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

<?php 
	$a = &#39;abc&#39;; 
	$b = &#39;a&#39;; 
	echo $$b; // 印出 abc 
	 
Copy after login

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

<?php 
	define(&#39;PKEY1&#39;, &#39;abc&#39;); 
	define(&#39;PKEY2&#39;, &#39;def&#39;); 
	$i = 1; 
	$a = &#39;PKEY&#39;; 
	echo constant($a . $i); // abc 
	echo constant($a . ++$i); // def 
	 
Copy after login

教程地址:

欢迎转载!但请带上文章地址^^

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!