Answers for "vriadic function in php"

PHP
0

vriadic function in php

<?php

function sum(int ...$numbers): int
{
    $total = 0;
    for ($i = 0; $i < count($numbers); $i++) {
        $total += $numbers[$i];
    }

    return $total;
}
Code language: PHP (php)
Posted by: Guest on May-03-2022
0

vriadic function in php

<?php

function sum(...$numbers)
{
    $total = 0;
    for ($i = 0; $i < count($numbers); $i++) {
        $total += $numbers[$i];
    }

    return $total;
}
echo sum(10, 20) . '<br>'; // 30
echo sum(10, 20, 30) . '<br>'; // 60
Code language: PHP (php)
Posted by: Guest on May-03-2022
0

vriadic function in php

<?php

function sum(int ...$numbers): int
{
    return array_sum($numbers);
}
Code language: PHP (php)
Posted by: Guest on May-03-2022

Browse Popular Code Answers by Language