Пример #1
0
<html>
  <head>
    <!-- Created by JohnKagga http://johnkagga.me -->
      <title> Functions </title>
  </head>
    <body>
      <!-- function without an argument -->
        <?php 
function sayName()
{
    echo "My name is John Kagga <br>";
}
sayName();
?>
      <!-- function with an argument -->
        <?php 
function sayName2($name)
{
    echo "My name is {$name} <br>";
}
sayName2("John");
sayName2("Kagga");
?>
    </body>
</html>
Пример #2
0
<?php

function sayName($name, $name1, $name2)
{
    echo "Hello {$name}" . ($name1 + $name2);
}
$vasay = "Brata";
sayName($vasay, 23, 12);
function add($arg, $arg2)
{
    $sum = $arg + $arg2;
    return $sum;
}
echo "<br>";
$result = add(23, 23);
$result2 = add(23, $result);
echo "My bunny is " . $result2;
function subt($val1, $val2)
{
    $add = $val2 + $val1;
    $subt = $val2 - $val1;
    return array($add, $subt);
}
echo "<br>";
$result = subt(12, 4);
echo "Add : " . $result[0] . "<br>";
echo "Subt : " . $result[1];
echo "<br>";
list($result_add, $result_subt) = subt(12, 123);
//Для извлечения сразу нескольких значений из функции
echo "Add : " . $result_add . "<br>";