PHP 允 许 用 户 象 使 用 常 规 变 量 一 样 使 用 环 境 变 量 。 例 如 , 在 页 面
http://www.nba.com/scores/index.html
中包含如下代码:
< ?php
echo “[$REQUEST_URI]”
;
? >
则输出结果为[/scores/index.html]
C.
数组
用户在使用 PHP 创建数组时,可以把数组索引(包括常规索引或关联索引)加入方括号
中。例如:
$fruit[0] = ‘banana’;
$fruit[1] = ‘apple’;
$favorites['animal'] = ‘tiger’;
$favorites['sports'] = ‘basketball’;
如果用户在向数组赋值时不指明数组下标,PHP 将自动把该对象加入到数组末尾。例
如对于上述$fruit
数组可以用以下方式赋值而保持结果不变,
$fruit[] = ‘banana’;
$fruit[] = ‘apple’;
同样,在 PHP
中,用户还可以根据需要建立多维数组。例如:
$people[‘David’][‘shirt’] = ‘blue’;
$people[‘David’][‘car’] = ‘red’;
$people[‘Adam’][‘shirt’] = ‘white’;
$people[‘Adam’][‘car’] = ‘silver’;