首頁  >  文章  >  後端開發  >  PHP extract() 函數用法舉例

PHP extract() 函數用法舉例

WBOY
WBOY原創
2016-07-25 08:57:441332瀏覽
  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