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. Link to comment https://forums.phpfreaks.com/topic/110157-passing-unlimited-arguments/ 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 Link to comment https://forums.phpfreaks.com/topic/110157-passing-unlimited-arguments/#findComment-565327 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. Link to comment https://forums.phpfreaks.com/topic/110157-passing-unlimited-arguments/#findComment-565328 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! Link to comment https://forums.phpfreaks.com/topic/110157-passing-unlimited-arguments/#findComment-565333 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? Link to comment https://forums.phpfreaks.com/topic/110157-passing-unlimited-arguments/#findComment-565357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.