PHP Knowledge 2

字符串数组的默认值为””

””在条件表达式中为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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值