RE: [PHP] Easy Function Question?

From: Date: Wed, 11 Sep 2002 00:21:53 +0000
Subject: RE: [PHP] Easy Function Question?
Groups: php.general 
Request: Send a blank email to php-general+get-115915@lists.php.net to get a copy of this message
Martin, so if I write... function myFunction($name, $phone, $zip="6666"){ echo $name.$phone.$zip } and $zip is NOT SET then $zip will = 6666. But if $zip IS SET then $zip will = whatever $zip's current value is, and will NOT be changed to 6666? Please advise. Thanks Martin -----Original Message----- From: Martin Towell [mailto:martin.towell@world.net] Sent: Tuesday, September 10, 2002 5:14 PM To: Shane; php-general@lists.php.net Subject: RE: [PHP] Easy Function Question? function myFunction($name, $phone, $zip="6666"){ echo $name.$phone.$zip } is the corrent format, but if you call it like this: myFunction("name", "phone", null); then $zip will equal null, not "6666" something like this might help function myFunction($name, $phone, $zip="6666"){ if (!$zip) $zip = "6666"; echo $name.$phone.$zip } HTH Martin -----Original Message----- From: Shane [mailto:shane@delaplaine.com] Sent: Wednesday, September 11, 2002 10:14 AM To: php-general@lists.php.net Subject: [PHP] Easy Function Question? I have a need to call a function, where all the variables used might not be set. Is there a way to have a variable in a function have a default setting if the variable passed to the function is VOID? EXAMPLE: $name="me"; $phone="5555"; //$zip is VOID function myFunction($name, $phone, $zip){ echo $name.$phone.$zip } can I write...? function myFunction($name, $phone, $zip="6666"){ echo $name.$phone.$zip } and then $zip will have a value of 6666 if $zip is VOID for some reason...? I thought it was something like this, but I keep batting ZERO and there is no mention of this problem in the places I looked in the docs. Can anyone throw me a bone? Thanks gang! -NorthBayShane -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#115915) next »