RE: [PHP] function with 2 arguments

From: Date: Mon, 19 Feb 2001 19:26:01 +0000
Subject: RE: [PHP] function with 2 arguments
Groups: php.general 
Request: Send a blank email to php-general+get-40614@lists.php.net to get a copy of this message
> Hi, I'm about to make a function with two arguments, and I > want the second one to be optional. Can I just write the function > and use it with one or two arguments without problems (I check > if the second argument was passed inside the function). > Is this OK? To make the second argument optional, you should declare the function as such: function myFunc( $firstArgument, $secondArgument = "" ) { } The above is defaulting the second argument to nothing/null/no value. You could default to any value you wish. If the argument is not passed, the default value will be used, whatever it is set to. Chris

« previous php.general (#40614) next »