字符串数组的默认值为””
””在条件表达式中为flase,非空串为true
数组的下标不能为负数
<HTML>
<HEAD>
<TITLE>一个简单的数组</TITLE>
</HEAD>
<FONT SIZE=5>
<B>
<?
/*定义数组$Cities[]*/
$Cities[-1] = "武汉";
//不会报错,但Cities[-1]不能被使用,否则出错
#$Cities[0] = "北京";
$Cities[1] = "天津";
$Cities[2] = "上海";
$Cities[3] = "深圳";
$Cities[100] = "深圳100";
//未被设置的元素默认为""
if($Cities[0] == "")
echo "Cities[0] was not setted and it equal to /"/"/n<BR>"; //go here
else
echo "Cities[0] not be setted and it NOT equal to /"/"/n<BR>";
//被设置成””的元素,在条件表达式中为false
if($Cities[0] = "")
echo '$Cities[0] = "" return true<BR>';
else
echo '$Cities[0] = "" return false<BR>'; //go here
//被设置成非空串的元素,在条件表达式中为true
if($Cities[0] = "AAA")
echo '$Cities[0] = "AAA" return true<BR>'; //go here
else
echo '$Cities[0] = "AAA" return false<BR>';
print("我住在$Cities[500]。<BR>/n");
//打印$Cities[500],因为未定义初值,因此为””
//print("$Cities[-1]"); //出错数组下标不能小于0
?>
</B>
</FONT>
</BODY>
</HTML>