note 8983 modified in functions.arguments by felipe

From: Date: Mon, 21 Jul 2008 01:54:24 +0000
Subject: note 8983 modified in functions.arguments by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142397@lists.php.net to get a copy of this message
if you compiled with "--enable-track-vars" then an easy way to get variable function args is to use extract(). <?php $args = array("color" = "blue","number" = 3); function my_func($args){ extract($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. or <?php function my_func($HTTP_POST_VARS){ extract($HTTP_POST_VARS); // use all your vars by name! } ?> --was-- 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){ extract($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. or function my_func($HTTP_POST_VARS){ extract($HTTP_POST_VARS); // use all your vars by name! } http://php.net/manual/en/functions.arguments.php

« previous php.notes (#142397) next »