I am trying to work out how to write php functions, so that I don\'t have to keep writing a block of code over and over again, I am having a play around and tried writing th
Firstly, you need to pass in the $greeting variable for it to be in the functions scope - see the PHP manual for variable scope. It is best avoid using global
s as they are harder to debug and test.
Secondly, you have missed out the assignment for the $greeting
variable.
Thirdly, you have forgotten to return the value from the function so it can be echo
d out. See the PHP manual for functions.
Fourth, $2nd
is not a valid variable name. Variables must start with a letter. See the relevant manual page.
$greeting = 'Hello';
function frank ($greeting) {
$return = '';
$name = 'frank';
$second = 'robson';
$return .= $greeting;
$return .= $name;
$return .= $second;
return $return;
}
echo frank($greeting);