Home > Archive > PHP on Windows > August 2004 > optional function parameters
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
optional function parameters
|
|
| Ragnar 2004-08-09, 8:59 am |
|
Hi guys,
another quick one. I was wondering what you'd have to do
with a function, so it would be able to have 'optional' parameters
when calling it.
much like:
string substr ( string string, int start [, int length])
where you can just omit the [, in length] part if you want.
What do you have to do in your own functions to allow for
something like that ?
cheers,
Ben
--
NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler!
GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl
| |
| Nadim Attari 2004-08-09, 8:59 am |
| > another quick one. I was wondering what you'd have to do
> with a function, so it would be able to have 'optional' parameters
> when calling it.
>
> much like:
>
> string substr ( string string, int start [, int length])
>
> where you can just omit the [, in length] part if you want.
> What do you have to do in your own functions to allow for
> something like that ?
<?php
function myFunction ($argOne, $argTwo = 'defaultTwo', $argThree =
'defaultThree')
{
echo '$argOne: ' . $argOne . ' - ';
if ($argTwo == 'defaultTwo')
echo 'probably $argTwo was not provided - ';
else
'$argTwo : ' . $argTwo . ' - ';
if ($argThree == 'defaultThree')
echo 'probably $argThree was not provided - ';
else
'$argThree : ' . $argThree . '<br>';
}
myFunction ('One' , 'Two', 'Three');
myFunction ('One' , 'Two', '');
myFunction ('One' , '', '');
myFunction ('' , '', '');
myFunction ('One' , 'Two');
myFunction ('One');
?>
|
|
|
|
|