• PHP Video Tutorials

PHP - Ds Vector sum() Function



Ds\Vector::sum() function can return the sum of all values in a vector.

Syntax

public number Ds\Vector::sum( void )

Ds\Vector::sum() function doesn't have any parameters.

Ds\Vector::sum() function can return the sum of all values in a vector as either float or int depending on the values in a vector.

Example 1

<?php 
   $array = new \Ds\Vector([5, 2, 1, 4, 8, 6]); 
   
   echo("The original vector: \n"); 
   var_dump($array); 
   
   echo("\n The sum of elements: \n"); 
   var_dump($array->sum()); 
?>

Example 2

<?php 
   $array = new \Ds\Vector([2.5, 5, 1, 3.6, 7, 4.3]); 
   
   echo("The original vector: \n"); 
   print_r($array); 
   
   echo("\n The sum of elements: \n"); 
   print_r($array->sum()); 
?>
php_function_reference.htm
Advertisements