Parameters and Arguments - Fucntions (Bug)


#1

There is something wrong.
Someone can help?
There is my code:

<?php
$name= "Iris";
function greetings($name) {
echo "Greetings," . $name ."!".

greetings();
}
?>

Then when I try to go on the site says:

"Ops, . It looks like nothing was printed! Did you remember to call your function? (Check the Hint if you need help.)"

What should I do?


#2

Should be,

greetings("Iris")

or

greetings($name)

The parameter is shadowing the global variable. The names may be the same, but they are two different variables.

echo "Greetings, " . $name ."!";

Note two changes... space after comma in string expression. Semi-colon at end of statement instead of full stop (period).


#3

Wow thanks man! it works <3


#4

As an aside, PHP permits string interpolation when we use double quotes.

How it must be written when single quotes are used (concatenation).

echo 'Greetings, ' . $name . '!';

How it may be written when double quotes are used (interpolation):

echo "Greetings, $name!";

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.