首页  >  文章  >  后端开发  >  PHP extract() 函数用法举例

PHP extract() 函数用法举例

WBOY
WBOY原创
2016-07-25 08:57:441340浏览
  1. //导出数组为变量
  2. $a = 'Original';
  3. $my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
  4. extract($my_array); // bbs.it-home.org
  5. echo "\$a = $a; \$b = $b; \$c = $c";
  6. ?>
复制代码

输出结果: $a = Cat; $b = Dog; $c = Horse

例2,使用全部参数:

  1. $a = 'Original';

  2. $my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
  3. extract($my_array, EXTR_PREFIX_SAME, 'dup');

  4. echo "\$a = $a; \$b = $b; \$c = $c; \$dup_a = $dup_a;";

  5. ?>
复制代码

输出结果: $a = Original; $b = Dog; $c = Horse; $dup_a = Cat;



声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn