示例#1
0
# func_get_args & func_num_args
function somaTudo()
{
    $lista = func_get_args();
    $qntd = func_num_args();
    $total = 0;
    // 1 método
    //for ($i = 0; $i < $qntd; $i++) {
    //	$total += $lista[$i];
    //}
    // 2 método
    foreach ($lista as $item) {
        $total += $item;
    }
    echo "<br> {$total}";
}
somaTudo(1, 2, 3, 4, 5, 6);
# Funções variádicas
function media(...$valores)
{
    $total = array_sum($valores) / count($valores);
    return $total;
}
echo "<br>" . media(10, 10, 10);
# Retorno de Valores
function cubo($num)
{
    $x = $num * $num * $num;
    return $x;
}
echo "<br>" . cubo(5);
示例#2
0
<?php

include_once "{$_SERVER['DOCUMENT_ROOT']}/workspace/Estudos/head.php";
include_once $_SERVER['DOCUMENT_ROOT'] . '/workspace/Estudos/functions/html.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/workspace/Estudos/menu.php';
if (isset($_POST['enviar'])) {
    echo '<h1>A soma dos números é: ' . somaTudo(10) . '</h1>';
} else {
    gerarInputNumero(10);
}