How to do Parameters and Arguements?


#1

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







<?php
$name = "Senor";

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

    ?>
  </p>
</body>


#2

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.

greetings("Senor");

"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).


#3

Thank you!
This really helped!