php定义变量

1.引用全局变量

1

1 <?php

2  $var=0;

3  function test($index)

4  {

5      global $var;

6      $var=$var+1;

7      echo "The ".$index." number is ".$var."<br>";

8  }

 test(1);

10  test(2)

11 ?>

2

1 <?php

2  $var=0;

3  function test($index)

4  {

5     

6      $GLOBALS["var"]=$GLOBALS["var"]+1;

7      echo "The ".$index." number is ".$GLOBALS["var"]."<br>";

8  }

9  test(1);

10  test(2)

11 ?>

2.定义常量

bool define ( string name, mixed value [, bool case_insensitive] )

name 为常量名,value为常量的值。case_insensitive]为大小写敏感。默认为敏感。例如:

1 <?php

2 define("CONSTANT", "Hello world.");

3 echo CONSTANT; // outputs "Hello world."

4 echo Constant; // outputs "Constant" and issues a notice.

原文:

http://www.cnblogs.com/confach/articles/470492.html

posted @ 2012-10-21 22:23  浪里飞  阅读(244)  评论(0编辑  收藏  举报