看看以下内容:
文件1.php
$a = 1;
$$a = "one"; // $1 = one
var_dump( ${'1'} ); // string(3) "one"
$str = "1=_one&foo=bar";
parse_str($str);
var_dump( ${'1'}, $foo );
// string(3) "one"
// and not "_one", so apparently $1 is not overwritten by parse_str
print_r( get_defined_vars() );
/*
Array(
[a] => 1
[1] => one <----- index is 1
[str] => 1=_one&foo=bar
[1] => _one <----- index is 1, again ?!?
[foo] => bar
);*/
文件2.php
$str = "1=_one&foo=bar";
parse_str($str);
var_dump( ${'1'}, $foo ); // will give "undefined variable: 1" and string(3) "bar"
print_r( get_defined_vars() );
/* if you run this from the command line you may have more variables in here:
Array(
[a] => 1
[str] => 1=_one&foo=bar
[1] => _one <--- variable 1 is defined here
[foo] => bar
);*/
- 怎么可能有一个重复的数组索引?(参见文件 1 的示例)。
- 为什么在第二个示例中,变量
$1
未定义但确实出现在get_defined_vars()
数组中?我如何访问它? - 在示例 1 中,为什么
$1
不被 覆盖parse_str
?