Symbols Table

compact($m1[,$m2……]) returns an array containing all variables named in $m1……extract (&$arr[,$i=EXTR_OVERWRITE[,$s=NULL]]) imports variables from an array into the symbols table. $i can be EXTR_OVERWRITE, EXTR_SKIP, EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, EXTR_PREFIX_INVALID, EXTR_IF_EXISTS, EXTR_PREFIX_IF_EXISTS, EXTR_REFS. $s is the prefix attached to a variable name.

<!DOCTYPE html><html><head></head>
<body>
<?php

$v1=1; $v2=2; $v3=3; $v4=4; $v5=5; $v6=6;
print_r(compact('v1',['v2','v3',['v4','v5']],'v6'));
echo "<br />";

$a=["c"=>"lemon","orange","banana"];
extract($a,EXTR_PREFIX_INVALID,'v');
echo "$c $v_0 $v_1 <br />";

$b=["v_0"=>"watermelon","v_1"=>"apple","v_2"=>"pear"];
extract($b,EXTR_SKIP|EXTR_REFS);
                                                  // skip if names collide; ref.
echo "$v_0 $v_1 $v_2 <br />";

$v_2="mango";
echo $b["v_2"];

?></body></html>

Array ( [v1] => 1 [v2] => 2 [v3] => 3 [v4] => 4 [v5] => 5 [v6] => 6 ) 
lemon orange banana 
orange banana pear 
mango