Example #1
0
<?php

function myAge($birthYear)
{
    // defines a function, this one is named "myAge"
    $yearsOld = date('Y') - $birthYear;
    // calculates the age
    return $yearsOld . ' year' . ($yearsOld != 1 ? 's' : '');
    // returns the age in a descriptive form
}
echo 'I am currently ' . myAge(1981) . ' old.';
// outputs the text concatenated
// with the return value of myAge()
// As the result of this syntax, myAge() is called.
?>

Example #2
0
/* multi line or inline comment */
echo "Hello world\n";
// variable names are case sensitive
// function and class names are not !!!!!
echo NULL == NULL;
echo NULL == false;
// they are !!!
echo "\n";
// $birthYear, yearsOld are case sensitive
function myAge($birthYear)
{
    // function 'date' or 'DATE' case insensitive
    $yearsOld = dAtE('Y') - $birthYear;
    return $yearsOld . ' year' . ($yearsOld != 1 ? 's' : '');
}
echo 'I am currently ' . myAge(1981) . " old.\n";
echo 'I am currently ' . MYAGE(1981) . " old.\n";
echo function_exists('myAge') . "\n";
// can be handy
// lambda expression / closures
function getAdder($x)
{
    return function ($y) use($x) {
        return $x + $y;
    };
}
$adder = getAdder(8);
echo $adder(2) . "\n";
class Person
{
    public static $count = 0;