• 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.
  • 相关阅读:
    [公告]博客园准备建立SharePoint团队
    [公告]新增三款Skin
    又新增三款Skin
    一个不错的计数器
    [公告]新建新手区
    2005年1月16日 IT Pro 俱乐部活动纪实
    [好消息]祝成科技.微软公司.博客园联合打造IT俱乐部
    [公告]SharePoint团队正式成立
    SharePoint文档库存在问题
    [活动]2004年计算机图书评选
  • 原文地址:https://www.cnblogs.com/zhangjun516/p/2883230.html
Copyright © 2020-2023  润新知