Write a PHP program to capture a variable number of arguments to a given function
<?php //Licence: https://bit.ly/2CFA5XY function variadicFunction($operands) { $sum = 0; foreach($operands as $singleOperand) { $sum += $singleOperand; } return $sum; } var_dump(variadicFunction([1, 2])); var_dump(variadicFunction([1, 2, 3, 4])); ?>
Sample Output:
int(3) int(10)
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer