Jump to content

NewbieQ: passing value to function


scanreg

Recommended Posts

Am just starting to learn PHP  ???  ::)

 

I have the following function:

 

function dino($fred) {

return $fred *= 2;

}

$wilma = 6;

$barney = dino($wilma);

echo "\$wilma is: $wilma<br />";

echo "\$barney is: $barney";

 

If you have $wilma = 6; why isn't it $wilma above in the function instead of $fred ?

 

In other words, how does the script/php know to insert the value of $wilma into the function if it's $fred that is mentioned in the function, not $wilma ?

 

Many thanks  :)

Link to comment
Share on other sites

The parameter name in the function definition is the variable name that the function will use to reference that parameter inside the function. When the function is called, the parameter can be supplied from anything - string, number, expression, variable, or another function call.

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.