Bonjour Shane,

Le mercredi 11 septembre 2002 à 11:21:53, vous écriviez :

S> Martin, so if I write...

S> function myFunction($name, $phone, $zip="6666"){
S>  echo $name.$phone.$zip
S> }

S> and $zip is NOT SET then $zip will = 6666.
S> But if $zip IS SET then $zip will = whatever $zip's current value is, and will NOT 
be changed to 6666?

S> Please advise.
S> Thanks Martin

S> -----Original Message-----
S> From: Martin Towell [mailto:[EMAIL PROTECTED]]
S> Sent: Tuesday, September 10, 2002 5:14 PM
S> To: Shane; [EMAIL PROTECTED]
S> Subject: RE: [PHP] Easy Function Question?


S> function myFunction($name, $phone, $zip="6666"){
S>  echo $name.$phone.$zip
S> }

S> is the corrent format, but if you call it like this:

S> myFunction("name", "phone", null);

S> then $zip will equal null, not "6666"
S> something like this might help

S> function myFunction($name, $phone, $zip="6666"){
S>  if (!$zip)  $zip = "6666";
S>  echo $name.$phone.$zip
S> }

S> HTH
S> Martin

Why don't you just try ? ;-)

S> -----Original Message-----
S> From: Shane [mailto:[EMAIL PROTECTED]]
S> Sent: Wednesday, September 11, 2002 10:14 AM
S> To: [EMAIL PROTECTED]
S> Subject: [PHP] Easy Function Question?


S> I have a need to call a function, where all the variables used might not be
S> set. Is there a way to have a variable in a function have a default setting
S> if the variable passed to the function is VOID?

S> EXAMPLE:

S> $name="me";
S> $phone="5555";
S> //$zip is VOID

S> function myFunction($name, $phone, $zip){
S>  echo $name.$phone.$zip
S> }

S> can I write...?

S> function myFunction($name, $phone, $zip="6666"){
S>  echo $name.$phone.$zip
S> }

S> and then $zip will have a value of 6666 if $zip is VOID for some reason...?

S> I thought it was something like this, but I keep batting ZERO and there is
S> no mention of this problem in the places I looked in the docs.

S> Can anyone throw me a bone?
S> Thanks gang!

S> -NorthBayShane




-- 
Cordialement,
 Haj                            mailto:[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to