PHP Variable Argument Function

Program 1

<html>
    <head><title>PHP Var args</title>
    <body>
     <center>
  
<?php
       function myDisplay(...$values)  // var args
      {
           $sum=0;
           for($i=0;$i<count($values);$i++)
           {
            echo $values[$i];
            $sum=$sum+$values[$i];
            echo "<br>";
           }
           echo "Sum is:  ".$sum;
      } 
      
      myDisplay(50,20,28,10,34,67,44,77,88,99);
      echo "<br>------------------------------------------<br>";
      myDisplay(110,120,128,130,324,);
?>
</center>
</body>
</html>

Program 2

<html>
    <head><title>PHP Var args</title>
    <body>
     <center>
  
<?php
       function myDisplay($name, ...$values)  // var args
      {
        
        for($i=0;$i<count($values);$i++)
        {
            echo $values[$i];
            echo "<br>";
        }

     }
        
      myDisplay("Nilu","Amit","Rahul","Vijay"); 
      
      
?>
</center>
</body>
</html>
courses

Leave a Reply

Your email address will not be published. Required fields are marked *