PHP 06
PHP 06
}
• Modularised code can user echo "<br/>";
parameters }
Functions can modularise code
function stringburst($txt,$number)
{
for ($i=1; $i<=$number; $i++)
{
echo $txt;
}
echo "<br/>";
}
echo "Hello"
• In the code the function can appear
like a statement
stringburst("Ho", 7);
echo "Goodbye";
• It can DO something
Returning Values
return $answer;
}
Returning Values
function averageof2 ($num1, $num2)
{
• A function can return a value
{
• A function can return a value
{
• The scope of variables declared in a
function does not extend beyond $answer = ($num1 + $num2)/2;
the function
return $answer;
• They don't exist outside the function
}
{
• Changes made to parameters with
the function have no effect outside it
}
function oneless ($number)
echo $x; 19
Passing Variables by Value
• Changes made to the variable inside the function have no effect on the
original variable value
return $number;
• The function works with the original
assed variable
}