Jump to content

Simple:passing null value to function


johnsmith153

Recommended Posts

function display_details($name, $department="sales", $sex="male") {
   return "You are {$name} from {$department} and you are {$sex}";
}

 

I need to use the default value for $department, but none of the below work. How do I do it?

 

echo $display_details("Sally", NULL, "female"); // sets $department as empty/blank

 

echo $display_details("Sally", "", "female"); // sets $department as empty/blank

 

echo $display_details("Sally", , "female"); // PHP error

 

 

Link to comment
Share on other sites

you could reverse gender and department, since you don't seem to be omitting gender anywhere there..

 

However, if you want a variable length argument list you could look into:

 

func_num_argsfunc_get_args, and func_get_args

 

func_num_args will tell you how many arguments were specified..

 

func_get_args will get an argument by index

 

func_get_args will get all of the arguments

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.