PHP extract array function

Last Updated: February 20, 2022

extract — Get keys of the arrays as variable name and value of the key become value of the variable

The extract() function imports variables into the local symbol table from an array.

Syntax

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

Supports (PHP 4 , PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
value An associative array

Return Value

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

Example

$a = "Original";
$my_array = array("a" => "One","b" => "Two", "c" => "Three");
extract($my_array);
echo "\$a = $a; \$b = $b; \$c = $c";

Output

$a = One; $b = Two; $c = Three
Test