RE: [PHP] Optional Parameter ?

From: Date: Wed, 21 Mar 2001 10:42:41 +0000
Subject: RE: [PHP] Optional Parameter ?
Groups: php.general 
Request: Send a blank email to php-general+get-44919@lists.php.net to get a copy of this message
Or you can use an array: function print_this( $ArrayValues ) { do whatever using count($ArrayValues) to determine the bounds of the array; } -----Original Message----- From: Neil Kimber [mailto:neil.kimber@flytxt.com] Sent: 21 March 2001 11:44 To: Stewart Taylor; 'Jack Sasportas'; php-general@lists.php.net Subject: RE: [PHP] Optional Parameter ? Alternatively, you can use the approach below. There are different benefits from each approach. The following approach is particularly useful if you want an unlimited number of parameters (like elipses in C). function print_this ($value1, $value2) { if (3==func_num_args()) { $maybe3=func_get_arg(2); // args are counted from 0 up } .. .. } -----Original Message----- From: Stewart Taylor [mailto:Stewart.Taylor@uk.thalesgroup.com] Sent: 21 March 2001 08:53 To: 'Jack Sasportas'; 'php-general@lists.php.net' Subject: RE: [PHP] Optional Parameter ? You can give $maybe3 a default value which will be used if it is not passed in the function call. You can only do this for the last parameter in the function. function print_this ($value1, $value2, $maybe3=false) { do whatever if ($maybe != false) do whatever with $maybe } -Stewart -----Original Message----- From: Jack Sasportas [mailto:jack@innovativeinternet.com] Sent: 21 March 2001 08:42 To: php Subject: [PHP] Optional Parameter ? Is it possible to have a function that looks something like function print_this( $value1, $value2, $maybe3) { do whatever; } that would expect $value1, $value2 BUT would not care if $maybe3 came in or not ? and not give an error message that there is a missing paramter ? I know I can do a condition within the function, but just want to see if there is a more technical approach as in from php to ignore that optional per say variable. I did look in my PHP book by wrox, but no luck. Thanks !!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#44919) next »