今天看代码,看到这个函数发现没有见过,泪奔啊 说说这个函数的用法extract(array,extract_rules,prefix)
$a = 'Original'; $my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse"); extract($my_array); echo "\$a = $a; \$b = $b; \$c = $c";
上面会将$a直接覆盖,重新赋值
一般是将查询结果直接输出来直接可以用这个字段名
<?php
$a = 'Original';
$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
extract($my_array, EXTR_PREFIX_SAME, 'dup');
echo "\$a = $a; \$b = $b; \$c = $c; \$dup_a = $dup_a;";
?>
上面输出的是
$a = Original; $b = Dog; $c = Horse; $dup_a = Cat; 函数第二个和第三个参数都是可选参数