extract

FunctionParams and return types changed in PHP 8.0

Import variables into the current symbol table from an array.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1-8.2
PHP 8.3
PHP 8.4
PHP 8.5

extract Function synopsis

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

Parameters

$array

Passed by referenceTypearray

An associative array. This function treats keys as variable names and values as variable values. For each key/value pair it will create a variable in the current symbol table, subject to $flags and $prefix parameters.

$flags

OptionalTypeintDefault valueEXTR_OVERWRITE

The way invalid/numeric keys and collisions are treated is determined by the extraction $flags. It can be one of the following values:

$prefix

OptionalTypestringDefault value""

Note that $prefix is only required if $flags is EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID or EXTR_PREFIX_IF_EXISTS. If the prefixed result is not a valid variable name, it is not imported into the symbol table. Prefixes are automatically separated from the array key by an underscore character.

Note that the parameter $array is passed by reference, and contains additional/updated context data that may be useful.

Return value

Typeint

Returns the number of variables successfully imported into the symbol table.

Changes to the extract Function

PHP 8.0

  • Return type added: int
  • Parameter name of parameter #1 changed: $arg to $array
  • Parameter type added for parameter #1 ($array): array
  • Parameter name of parameter #2 changed: $extract_type to $flags
  • Parameter type added for parameter #2 ($flags): int
  • Parameter default value added for position #2 ($flags): EXTR_OVERWRITE
  • Parameter type added for parameter #3 ($prefix): string
  • Parameter default value added for position #3 ($prefix): ""
  extract(
-     &$arg,
+     array &$array,
-     $extract_type,
+     int $flags = EXTR_OVERWRITE,
-     $prefix
+     string $prefix = ""
-   )
+   ): int

extract Function Availability

PHP VersionAvailability
PHP 8.5Upcoming Release Yes
PHP 8.4Supported (Latest) Yes
PHP 8.3Supported Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Security-Fixes Only Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes