-
-
$size = "old size"; //注意最后size变量的值。
- $a = array(
- "color" => "red",
- "size" => "XXL",
- "price" => "53");
- extract($a);
- echo "color = $color
";
- echo "size = $size
";
- echo "price = $price
";
- ?>
-
复制代码
输出结果:
color = red
size = XXL
price = 53
通过上例发现$size的值为XXL,而不是之前的”old size”,说明默认情况下当数组中的key与已有的变量冲突时,将覆盖原来的变量。
继续介绍extract函数的后两个可选参数。
第二个参数$extract_type是用来控制当发生冲突时的处理方法,可能的值为:
-
-
$a = array(
- "color" => "red",
- "size" => "XXL",
- "price" => "53");
- extract($a,EXTR_PREFIX_ALL,"SC");
- echo "color = $SC_color
";
- echo "size = $SC_size
";
- echo "price = $SC_price
";
- extract($a,EXTR_REFS);
- $color="green";
- echo $a['color']; //查看原数组的值
- ?>
复制代码
输出结果:
color = red
size = XXL
price = 53
green
|