How to do Parameters and Arguements?


What is wrong with my code? It won't print anything.

$name = "Senor";

    function greetings($name) {
        echo "Greetings, " .  $name . "!"; }



In the above, $name is the parameter. It is a locally defined and scoped variable that is a copy of the argument sent in the function call expression.


"Senor" is the argument. The function will copy this string into the $name variable and echo, Greetings, Senor! in the document.

By the same token, were your function to not have a parameter, it would be able to see your global variable, and would use it. This is called looking up the scope chain.

When the parameter exists, it is a different variable than the global, so over*shadows* it (meaning the function cannot see it in the scope chain).


Thank you!
This really helped!