You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
585 B
32 lines
585 B
<?php
|
|
|
|
//定义常量
|
|
define('a','1');
|
|
const b=2;
|
|
|
|
//调用常量,不需要$号
|
|
echo a.'<br>';
|
|
echo b.'<br>';
|
|
|
|
//b=3; //b是常量,不能再修改
|
|
//echo b;
|
|
|
|
//获取常量
|
|
$b='b';
|
|
echo constant($b).'<br>';
|
|
|
|
//判断常量是否存在
|
|
const c=3;
|
|
$d=4;
|
|
var_dump(defined('c')); //常量c存在,返回true
|
|
echo '<br>';
|
|
var_dump(defined('d')); //d不是常量,返回false
|
|
echo '<br>';
|
|
|
|
//魔术常量
|
|
echo "当前文件路径".__FILE__;
|
|
|
|
/*
|
|
感悟:php常量像C语言里的宏
|
|
*/
|
|
?>
|