PHP functions

A function is a block of statements that can be used repeatedly in a program.A function will not execute immediately when a page loads.A function will be executed by a call to the function.

Syntax
function functionName() {
    code to be executed;
}
Example:
<?php
function writeMsg() {
    echo "Hello world!";
}
writeMsg(); // call the function
?>

Functions - Returning values


To let a function return a value, use the return statement:

Example
<?php
function sum($x, $y) {
    $z = $x + $y;
    return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>

No comments:

| Designed by Harhiktech