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 this, but it doesnt work for some reason, can anyone tell me where I am going wrong ?.
<?php
$greeting 'Hello';
function frank ()
{
$name = 'frank';
$2nd = 'robson';
echo $greeting;
echo $name;
echo $2nd;
}
echo frank()
?>
Instead of echoing inside your function you should consider returning a string with it. Also prefer passing a parameter instead of using global scope :
Finally a variable name start with a letter or an underscore so
$2ndis not a valid name.See this this link for more info on naming variable