myron Posted March 1, 2007 Share Posted March 1, 2007 I have a function: function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page') I want to pass values for the first, second, and last arguments, but I want to use the default value for the third argument. How do I do that? Quote Link to comment https://forums.phpfreaks.com/topic/40703-functions-optional-arguments/ Share on other sites More sharing options...
monk.e.boy Posted March 1, 2007 Share Posted March 1, 2007 I don't think you can :( monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/40703-functions-optional-arguments/#findComment-196988 Share on other sites More sharing options...
trq Posted March 1, 2007 Share Posted March 1, 2007 You can't. Quote Link to comment https://forums.phpfreaks.com/topic/40703-functions-optional-arguments/#findComment-196992 Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 you are using the correct format for function function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page') it will do wht you need to do call the function like splitPageResults($query, $max_rows, '', $page_holder) Quote Link to comment https://forums.phpfreaks.com/topic/40703-functions-optional-arguments/#findComment-196993 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 maybe store the value in a global var and use that! Quote Link to comment https://forums.phpfreaks.com/topic/40703-functions-optional-arguments/#findComment-196996 Share on other sites More sharing options...
obsidian Posted March 1, 2007 Share Posted March 1, 2007 you are using the correct format for function function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page') it will do wht you need to do Did you read the OP? What he's after is not possible, really, just as the other two replies have said. @myron - Your best bet is to pass in a NULL and test for that within your actual function body. If it's empty, assign it your default value. Quote Link to comment https://forums.phpfreaks.com/topic/40703-functions-optional-arguments/#findComment-196998 Share on other sites More sharing options...
myron Posted March 1, 2007 Author Share Posted March 1, 2007 Thanks to everyone who replied. I'll try some of your suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/40703-functions-optional-arguments/#findComment-197048 Share on other sites More sharing options...
boo_lolly Posted March 1, 2007 Share Posted March 1, 2007 couldn't you write an 'if' statement inside the function to check if the parameter has been given, therefore handle the process differently? Quote Link to comment https://forums.phpfreaks.com/topic/40703-functions-optional-arguments/#findComment-197068 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.