php定义变量
2012-10-21 22:23
323 查看
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 }
9 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
法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 }
9 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
相关文章推荐
- PHP变量定义和输出
- PHP可变变量,预定义变量,综述,$_GET数组
- php 定义和引用变量 (一)
- PHP_零基础学php_2变量、预定义变量、预定义常量、表达式、运算符、程序控制流程
- dede定义全局变量(include/common.inc.php)及调用方式
- php中与请求路径相关的一些预定义变量的区别
- PHP_零基础学php_2变量、预定义变量、预定义常量、表达式、运算符、程序控制流程
- 判断php变量是否定义,是否为空,是否为真的一览表
- php 变量定义方法
- PHP学习之预定义变量(实例讲解)
- PHP中一些常用的预定义常量和变量
- 五、PHP知识核心 预定义变量(超全局变量/数组)
- php超全局数组(预定义变量)
- php 变量定义方法
- PHP 预定义变量
- PHP Global定义全局变量使用说明
- php源码之路第三章第三节( 预定义变量)
- PHP基础之变量定义
- PHP 7: PHP 变量和常量的定义
- php 变量未定义