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
https://forums.phpfreaks.com/topic/127713-newbieq-passing-value-to-function/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.