PHP | Ds\Vector sum() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The Ds\Vector::sum() function is an inbuilt function in PHP which returns the sum of all the elements of the vector. Syntax: number public Ds\Vector::sum( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the sum of all elements in the vector. The sum can be of int or float type depending on the vector elements. Below programs illustrate the Ds\Vector::sum() function in PHP: Program 1: PHP <?php // Declare the new Vector $arr = new \Ds\Vector([3, 6, 1, 2, 9, 7]); echo("Original vector:\n"); // Display the vector elements var_dump($arr); echo("\nSum of elements:\n"); // Use sum() function to returns the // sum of all vector elements var_dump($arr->sum()); ?> Output: Original vector: object(Ds\Vector)#1 (6) { [0]=> int(3) [1]=> int(6) [2]=> int(1) [3]=> int(2) [4]=> int(9) [5]=> int(7) } Sum of elements: int(28) Program 2: PHP <?php // Declare the new Vector $arr = new \Ds\Vector([3.5, 6, 1, 2.7, 9, 7.3]); echo("Original vector:\n"); // Display the vector elements print_r($arr); echo("\nSum of elements: "); // Use sum() function to returns the // sum of all vector elements print_r($arr->sum()); ?> Output: Original vector: Ds\Vector Object ( [0] => 3.5 [1] => 6 [2] => 1 [3] => 2.7 [4] => 9 [5] => 7.3 ) Sum of elements: 29.5 Reference: http://php.net/manual/en/ds-vector.sum.php Comment More infoAdvertise with us Next Article PHP | DsVector set() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector Similar Reads PHP DsMap sum() Function The Ds\Map::sum() function of PHP is used to get the sum of all of the values present in the Map instance. Syntax: number public Ds\Map::sum ( void ) Parameters: This function does not accepts any parameter. Return value: This function returns the sum of all of the values present in the Map instance 1 min read PHP DsSet sum() Function The Ds\Set::sum() function of Ds\Set class in PHP is an inbuilt function which is used to find the sum of all of the elements present in a Set. Syntax: number public Ds\Set::sum ( void ) Parameter: This function does not accepts any parameter. Return Value: This function returns the sum of the value 1 min read PHP | DsDeque sum() Function The Ds\Deque::sum() function is an inbuilt function in PHP which is used to return the sum of all elements present in the Deque. Syntax: public Ds\Deque::sum( void ) : number Parameters: This function does not accept any parameter. Return Value: This function returns the sum of all Deque elements. B 2 min read PHP | DsVector sum() Function The Ds\Vector::sum() function is an inbuilt function in PHP which returns the sum of all the elements of the vector. Syntax: number public Ds\Vector::sum( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the sum of all elements in the vector. The su 2 min read PHP | DsVector set() Function The Ds\Vector::set() function is an inbuilt function in PHP which is used to set the value in the vector at the given index. Syntax: void public Ds\Vector::set( $index, $value ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the 2 min read PHP | DsSet xor() Function The Ds\Set::xor() function is an inbuilt function in PHP which is used to create a new set which contains the value either in the first set or second set but not both. Syntax: Ds\Set public Ds\Set::xor ( Ds\Set $set ) Parameters: This function accepts a single parameter $set which is used to hold th 2 min read PHP | DsVector sort() Function The Ds\Vector::sort() function is an inbuilt function in PHP which is used to sort the elements of vector in-place. This will arrange the vector elements in increasing order. Syntax: void public Ds\Vector::sort( $comparator ) Parameters: This function accepts a single parameter $comparator which is 2 min read PHP | DsSequence sum() Function The Ds\Sequence::sum() function is an inbuilt function in PHP which is used to return the sum of all values of the sequence. Syntax: number abstract public Ds\Sequence::sum( void ) Parameters: This function does not accept any parameters. Return value: This function returns the sum of all sequence e 1 min read PHP | DsSequence set() Function The Ds\Sequence::set() function is an inbuilt function in PHP which is used to updates a value at a given index. Syntax: void abstract public Ds\Sequence::set ( int $index , mixed $value ) Parameters: This function accepts two parameters as mentioned above and described below: $index: It is used to 2 min read PHP | DsDeque remove() Function The Ds\Deque::remove() function is an inbuilt function in PHP which is used to remove and return the index value. Syntax: public Ds\Deque::remove( $index ) : mixed Parameters: This function accepts single parameter $index which holds the index of Deque for which the element is to be returned and rem 2 min read Like