defining optional variables within a function
Moderator: General Moderators
-
staypufinpc
- Forum Newbie
- Posts: 12
- Joined: Thu May 01, 2003 7:59 pm
defining optional variables within a function
I have created a number of successful functions with required arguments, but every time I try to create a variable with optional arguments it doesn't work. I get a parse error about missing a '(' somewhere but that never seems to be the case. They're simple functions, really. I just have some functions that output html forms. I'd like to pass optional arguments to show the form(s) filled out and whatnot. How do you correctly define optional arguments?
Code: Select all
<?php
function func($param, $optional1=0, $optional2='example')
{
echo $param, ' ', $optional1, ' ', $optional2;
}
func('a', 'simple');
?>http://www.php.net/manual/en/function.func-get-args.php
-
staypufinpc
- Forum Newbie
- Posts: 12
- Joined: Thu May 01, 2003 7:59 pm
IT worked
Thanks, I was trying: function func($param [, $optional1]]). Ooops.