extract ,eval的用法
mixed eval ( string $code_str ),
1 <?php 2 $string = 'cup'; 3 $name = 'coffee'; 4 $str = 'This is a $string with my $name in it.'; 5 echo $str. "\n"; 6 eval("\$str = \"$str\";"); 7 echo $str. "\n"; 8 ?>
eval 可以把变量值带到语句中输出,如果这个变量在应用之前没有赋予值,那么在eval后,该变量位置会为空,直接跳过该变量
int extract ( array $var_array [, int $extract_type = EXTR_OVERWRITE [, string $prefix ]] )
1 $array=array('a'=>'5','b'=>'1','c'=>'2'); 2 extract($array); 3 echo $a; 4 echo '<br/>'.$b; 5 echo '<br/>'.$c;
extract这个函数可以把数组的键名当作变量名,键值当作变量值,这个数组不能使索引数组,(php的变量命名规则),$extract_type的变量值时见下:
1 EXTR_OVERWRITE 2 If there is a collision, overwrite the existing variable. 3 EXTR_SKIP 4 If there is a collision, don't overwrite the existing variable. 5 EXTR_PREFIX_SAME 6 If there is a collision, prefix the variable name with prefix. 7 EXTR_PREFIX_ALL 8 Prefix all variable names with prefix. 9 EXTR_PREFIX_INVALID 10 Only prefix invalid/numeric variable names with prefix. 11 EXTR_IF_EXISTS 12 Only overwrite the variable if it already exists in the current symbol table, otherwise do nothing. This is useful for defining a list of valid variables and then extracting only those variables you have defined out of $_REQUEST, for example. 13 EXTR_PREFIX_IF_EXISTS 14 Only create prefixed variable names if the non-prefixed version of the same variable exists in the current symbol table. 15 EXTR_REFS 16 Extracts variables as references. This effectively means that the values of the imported variables are still referencing the values of the var_array parameter. You can use this flag on its own or combine it with any other flag by OR'ing the extract_type.