PHP extract() Function Guide & Examples
The purpose of the extract function is to convert key-value pairs from an array into variables and their values. In other words, the extract function takes the key of each element in the array as the variable name, the value of each element as the variable’s value, and imports them into the current symbol table.
For example, considering the following array:
$person = array("name" => "John", "age" => 30, "occupation" => "Engineer");
By using the extract function, it is possible to convert key-value pairs in an array into corresponding variables and variable values.
extract($person);
After the code above is executed, the following variables will be created:
$name = "John";
$age = 30;
$occupation = "Engineer";
At this point, you can directly use these variables without accessing their values through an array.