157 of 410 menu

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

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

Example

Let's extract variables from the array:

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

Code execution result:

1 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
byenru