1:$a='1';echo $a[0]的结果是什么?为什么?2:$a=1;echo $a[0]的结果是什么?为什么?

解决方案 »

  1.   

    http://www.php.net/manual/zh/language.types.string.php#language.types.string.substr访问和修改字符串中的字符字符串中的字符可以通过在字符串之后用花括号指定所要字符从零开始的偏移量来访问和修改。    Note: 为了向下兼容,仍然可以用方括号。不过此语法自 PHP 4 起已过时。 Example#3 一些字符串例子
    <?php
    // Get the first character of a string
    $str = 'This is a test.';
    $first = $str{0};
    // Get the third character of a string
    $third = $str{2};// Get the last character of a string.
    $str = 'This is still a test.';
    $last = $str{strlen($str)-1};// Modify the last character of a string
    $str = 'Look at the sea';
    $str{strlen($str)-1} = 'e';?>
    http://www.php.net/manual/en/language.types.string.php#language.types.string.substr
    Note: Accessing variables of other types using [] or {} silently returns NULL. 
      

  2.   

    估计一下
    第一个为1,
    第二为 null
      

  3.   

    整型不能通过索引访问,要想访问就要先将整型转换成字符串$a=123;
    $a=(string)$a;
    var_dump($a[1]);
      

  4.   

    太强了,PHP自动把字符串型变量给拆分了然后放到数组了??
    那以后根本就不用将字符串进行拆分放入数组了,因为PHP自动已经这样做了。
      

  5.   

    请看我在1楼的回贴,其中复制了PHP手册中的相关内容。
      

  6.   


    <?$a='日本';echo $a[0]?>