可能值得在文档中指出,并非所有关联(字符串)键都相同,以下代码的输出演示了这一点——这可能是向某些人介绍PHP自动类型转换的一个有用方法(并避免一些头痛)。
<?php
$r = array("0"=>"0","1"=>"1","" =>"2"," "=>"3");
echo 'PHP 如何看待这个数组: array("0"=>"0","1"=>"1","" =>"2"," "=>"3")',"\n-----------\n";
var_dump($r); print_r($r); var_export($r);
echo "\n-----------\n",'var_dump("0","1",""," ") = ',"\n-----------\n";
var_dump("0","1",""," ");
?>
输出
PHP 如何看待这个数组: array("0"=>"0","1"=>"1","" =>"2"," "=>"3")
-----------
数组(4) {
[0]=>
字符串(1) "0"
[1]=>
字符串(1) "1"
[""]=>
字符串(1) "2"
[" "]=>
字符串(1) "3"
}
数组
(
[0] => 0
[1] => 1
[] => 2
[ ] => 3
)
数组 (
0 => '0',
1 => '1',
'' => '2',
' ' => '3',
)
-----------
var_dump("0","1",""," ") =
-----------
字符串(1) "0"
字符串(1) "1"
字符串(0) ""
字符串(1) " "