Wolphie Posted June 14, 2008 Share Posted June 14, 2008 How would I pass unlimited arguments in a function? sprintf() is a clear example of what i'm trying to achieve. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 14, 2008 Share Posted June 14, 2008 See the three functions mentioned at this link - http://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 14, 2008 Share Posted June 14, 2008 Here's how I do it: function array_push_assoc(&$arr) { if (function_num_args() > 1) { $arrays = func_get_args(); foreach ($arrays as $k=>$v) { if ($k==0){continue;} foreach ($v as $key=>$val) { $arr[$key] = $val; } } } } That's an example function I wrote a while back for someone, lol. Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 14, 2008 Share Posted June 14, 2008 this sure is nice... i haven't tried passing variable length data (since i usually use array for this) but definitely this would come handy.. thanks! Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 14, 2008 Author Share Posted June 14, 2008 DarkWater: Could you possibly provide an example of it in use? Also, from what I can make out, it's still returned as an array, is it not possible to have unlimited arguments like sprintf() which isn't an array (i don't think) or have I misunderstood? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.