I would like to build some better functions. What I'm looking at doing is seperating out some of my often repeted code to a function lilbrary. The one I'm working on right now is for uploading files.
I would like to have the function return more than one bit of information, and was wondering if the only way to do that is to return as an array. And if that is the way can I call still pass the function several parameters?
Thanks
Yes, you'd need to return an array, and yes you can pass it as many parameters as you want to.
Cool thats what I was thinking, thanks
Also can I implement "optional" parameters? how?
Sure, you just put the default in the function
function blah($op1,$op2,$op3="default") { //blah }
May also want to take a look at [man]func_get_args[/man]. Comes in handy 😉
Really? So then I could call it with out $op3?
testit=blah(1,1);
would be valid and if I do pass a third in this example it would overide the default as above?
Yep. Try it out:
<?php function blah($op1,$op2,$op3="default") { echo $op1."<br />".$op2."<br />".$op3; } blah("test1","test2"); echo "<br /><br />"; blah("tst1","tst2","tst3"); ?>
Am now THANKS!!!
Looking good