Programming Tutorials

extract() in PHP

By: Dietricha in PHP Tutorials on 2011-10-28  

If you compiled with "--enable-track-vars" then an easy way to get variable function args is to use extract().

$args = array("color" = "blue","number" = 3);
function my_func($args){
echo $color;
echo $number;

the above strategy makes it real easy to globalize form data within functions, or to pass form data arrays to functions:

<input type="text" name="test[color]" value="blue">
etc, etc.

Then in your function, pass $test to extract() to turn the array data into global vars.

function my_func($HTTP_POST_VARS){
// use all your vars by name!

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)