<?php
// Say that we just submitted a POST form that had 5 fields, from test1 to test5. We // could put all the contents of $_POST into variables individually, like this.
$test1 =
$_POST["test1"];
$test2 =
$_POST["test2"];
$test3 =
$_POST["test3"];
$test4 =
$_POST["test4"];
$test5 =
$_POST["test5"];
// But extract() will let you do all of the above in a much easier way.
extract($_POST);
// You now have $test1, $test2, $test3, $test4, and $test5 by writing that one line. // However, say you have a different variable named $test4 and don't want to delete // it. This is where the optional arguements of extract() come in.
extract($_POST, EXTR_PREFIX_ALL,
"f_");
// The above function will make $f_test1, $f_test2, $f_test3, $f_test4, and $f_test5.
// There are a bunch of other choices other than EXTR_PREFIX_ALL, like
// EXTR_PREFIX_SAME, which only prefixes variables that already exist.