Re: optional function parameters
| From: | Nadim Attari | Date: | Mon, 09 Aug 2004 10:18:05 +0000 |
| Subject: | Re: optional function parameters | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-24371@lists.php.net to get a copy of this message | ||
> 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');
?>