Home  >  Article  >  Backend Development  >  PHP extract() function usage example

PHP extract() function usage example

WBOY
WBOYOriginal
2016-07-25 08:57:441331browse
  1. //Export the array as a variable
  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. ?>
Copy the code

Output results: $a = Cat; $b = Dog; $c = Horse

Example 2, using all parameters:

  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. ?>

Copy the code

output result: $a = Original; $b = Dog; $c = Horse; $dup_a = Cat;



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn