Using dynamic Constant and Define values ​​in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:48:09
Original
962 people have browsed it

Constant and Define are constants in php, so below I will introduce a method to dynamically use the Constant and Define value methods. I hope it will be helpful to all students.

PHP wants to show or use dynamic Constant / Define values, how to use it? ex: The following example is a dynamic variable, but how to use dynamic Constant?

The code is as follows
 代码如下 复制代码


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

Copy code



代码如下 复制代码

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

$a = 'abc'; $b = 'a'; echo $$b; // print abc ?>

PHP uses dynamic Constant / Define values ​​ You can use constant() to achieve the value of Constant, the example is as follows:
The code is as follows Copy code
define('PKEY1', 'abc'); define('PKEY2', 'def'); $i = 1; $a = 'PKEY';

echo constant($a . $i); // abc echo constant($a . ++$i); // def
?> http://www.bkjia.com/PHPjc/632795.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632795.htmlTechArticleIn PHP, Constant and Define are constants. So below I will introduce a method to achieve dynamic use of Constant and Define value methods. , I hope it will be helpful to all students. PHP To show off or use...
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 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!