Function Part II - Parameters and Arguments - Topic Question


#1

My code passed through fine, after several tries. However I'm trying to better understand the meaning or purpose of the code in bold pasted below.

<?php
$myname ="Alison";
function greetings($name){
echo "Greetings, " . $name . "!";
}
greetings($myname); <---- while the function above calculates my variables, what is the purpose of this code?
?>


#2
<?php
    $myname ="Alison"; 

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

Maybe it is not so good to see in this small example.
You give your function a parameter $name

With greetings($myname); you say greetings("Alison"); in your function now $name is "Alison"

If you didnt do that, in bigger pieces of code you must search all places where you called your function greetings() and change the parameter manually. Not so nice or? Better change only one Value from a variable and it is fine.

Hope that helped


#3

It helped Dookoo_De, thanks so much! :bulb: