PHP学习笔记-001:示例中了解常量以变量
echo PHP_VERSION."\n"; /* PHP内置常量:PHP_VERSION */
echo PHP_OS; /* PHP内置常量:PHP_OS */
echo "\n";
define("copyright","yangzhigang.cublog.cn"); /* 自定义常量:copyright */
define('pai',3.1415); /* 自定义常量:pai */
echo copyright;
echo "\n";
echo COPYRIGHT; /* 常量名区分大小写,copyright与COPYRIGHT不一样 */
echo "\n";
echo pai;
echo "\n";
class foo{ /* 定义一个class:foo */
function do_foo(){
echo "doing foo";
}
}
$bar=new foo();
$bar ->do_foo();
echo "\n";
function myfunc(){ /* 定义一个function:myfunc */
global $PHP_OS; /* 声明函数中引用全局的变最 */
echo PHP_OS;
}
myfunc();
echo "\n";
function func1(){
static $ha; /* 将变量静态化 */
$ha.="ha,";
echo $ha;
}
func1();
func1();
echo "\n";
$a = "hello";
$$a = "world"; /* 变量的变量 */
echo "$a,$hello";
echo "\n";
echo "$a,${$a}";
?>
阅读(8636) | 评论(0) | 转发(0) |