The extract Function

The extract function imports elements of an associative array into variables. The names of the variables will be the keys of the associative array.

Syntax

phpextract(array &$array, int $flags = EXTR_OVERWRITE, string $prefix = ""): int

Example

Let's extract variables from the array:

php<?php
  $arr = ['a' => 1, 'b' => 2, 'c' => 3];
  extract($arr);
  
  echo($a);
  echo($b);
  echo($c);
?>

Code execution result:

php1
2
3

See Also

  • the list function,
    which destructures an array into variables
  • the array_keys function,
    which returns the keys of an array
  • the in_array function,
    which checks if a value exists in an array