Home > AI > Language > PHP >

return value

Needless to specify return type

function square($num)
{
    return $num * $num;
}
echo square(4);   // outputs '16'.

Example 2: multiple return values

function small_numbers()
{
    return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
echo $zero;
echo $one;
echo $two;

Leave a Reply