Example 1 — Turn Array Keys into Variables
This example takes a small array of user data and creates one variable for each key.
<?php
$user = ["name" => "Asha", "city" => "Pune"];
$count = extract($user);
echo $name, PHP_EOL;
echo $city, PHP_EOL;
echo "Variables created: ", $count, PHP_EOL; How It Works
- $user has two keys, name and city.
- extract() creates the variables $name and $city from those keys.
- The variables can now be used directly, so echo prints Asha and Pune.
- extract() returned 2 because two variables were created.

