1 <?php 2 /* 3 声明全局变量global 4 */ 5 #单行注释 //同单行注释 6 $s="abcd"; 7 echo $s; 8 $b=20; 9 $a="tom"; 10 $copyA=&$a; 11 $b=52.29; 12 ?> 13 <?php 14 //定义常量 15 define("IP",3.1415,false); 16 echo IP; 17 18 $r=3; 19 $s=IP*3*$r; 20 echo $s; 21 22 define ("NAME","Tom"); 23 echo NAME;//outPut Tom 24 25 $name="tom" 26 function func() 27 { 28 global $name; 29 echo name; 30 global $na="bush"; 31 echo $na; 32 } 33 func();//调用func函数 34 echo $name; 35 echo $na; 36 $name="tom"; 37 echo $GLOBAL["name"];//使用全局变量数组 38 39 function fund() 40 { 41 static $i=1;//定义静态变量 42 $i=$i+1; 43 } 44 fund();//输出1 45 fund();//输出2 46 echo $i;//不在作用域内,无效 47 48 49 ?> 50 <?php 51 //变量输出 52 $name="Tom"; 53 $age=20; 54 echo $name,":",$age; 55 print($age); 56 ?> 57 <?= $age?>