newbtophp Posted August 10, 2010 Share Posted August 10, 2010 Im using func_get_args, but it gives an error?: Too few arguments?, when its correct (as the number of %s = the number of values within $args) <?php function sprintify() { global $urls; $args = func_get_args(); $input = $args[0]; unset($args[0]); return sprintf($urls[$input], implode(', ', $args)); } echo sprintify('default', 46, 464, 46); /* For your information: $urls['default'] = '%s/%s/%s'; */ ?> Link to comment https://forums.phpfreaks.com/topic/210319-func_get_args-doesnt-work/ Share on other sites More sharing options...
Mchl Posted August 10, 2010 Share Posted August 10, 2010 echo sprintify($urls['default'], 46, 464, 46); Link to comment https://forums.phpfreaks.com/topic/210319-func_get_args-doesnt-work/#findComment-1097500 Share on other sites More sharing options...
newbtophp Posted August 10, 2010 Author Share Posted August 10, 2010 echo sprintify($urls['default'], 46, 464, 46); Im trying to make the first parem the array key, and then that value of that array is extracted within the function, refer to the first post. Cheers Link to comment https://forums.phpfreaks.com/topic/210319-func_get_args-doesnt-work/#findComment-1097503 Share on other sites More sharing options...
Wolphie Posted August 10, 2010 Share Posted August 10, 2010 Try this: <?php function sprintify($args) { global $urls; $args = func_get_args(); $input = array_shift($args); return vsprintf($urls[$input], $args); } echo sprintify('default', 46, 464, 46); ?> Link to comment https://forums.phpfreaks.com/topic/210319-func_get_args-doesnt-work/#findComment-1097507 Share on other sites More sharing options...
newbtophp Posted August 10, 2010 Author Share Posted August 10, 2010 Gr8 Wolphie that worked Link to comment https://forums.phpfreaks.com/topic/210319-func_get_args-doesnt-work/#findComment-1097508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.