A function is just a name we give to a block of code that can be executed whenever we need it. When you create a function, you first need to give it a name, like myFunction.
Create Function
<?php
function myFunction(){
echo "Hello, We are vn4000!<br />";
}
?>
Using your Function
<?php
function myFunction(){
echo "We are vn4000!";
}
echo "Welcome to our homepage. ";
myCompanyMotto();
?>
Function Parameters
<?php
function myGreeting($name){
echo "Hello there ". $firstName . "!<br />";
}
myGreeting("vn4000");
?>
Function returning Values
<?php
function mySum($numX, $numY){
$total = $numX + $numY;
return $total;
}
$myNumber = 0;
echo "Before the function, myNumber = ". $myNumber ."<br />";
$myNumber = mySum(3, 4); // Store the result of mySum in $myNumber
echo "After the function, myNumber = " . $myNumber ."<br />";
?>