Foser Posted January 11, 2008 Share Posted January 11, 2008 I am wondering how to do this. I want to have a function which could have 3 variables, 5 or whatever number of variables. I want it to do all the same thing for each, how could a loop like this be done to check all variables that were set to the function eg. function NumberVariables($var, $var2, $var3); I want a loop which will due a code for all 3 but this function could also be used for any other number. Link to comment https://forums.phpfreaks.com/topic/85474-solved-looping-function-variables/ Share on other sites More sharing options...
teng84 Posted January 11, 2008 Share Posted January 11, 2008 i dont understand sorry ! but maybe you need to do define the default value of your func so no matter how many var they put it wotn produce an error eg. function teng($var ='x',$var2='x') is that what you mean? Link to comment https://forums.phpfreaks.com/topic/85474-solved-looping-function-variables/#findComment-436169 Share on other sites More sharing options...
trq Posted January 11, 2008 Share Posted January 11, 2008 <?php function foo() { $args = func_get_args(); foreach($args as $arg) { echo "Hello $arg\n"; } } foo('bob','jane','bill'); ?> Link to comment https://forums.phpfreaks.com/topic/85474-solved-looping-function-variables/#findComment-436170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.