Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
sum
communitycreator

What is the Ds\Set sum() function in PHP?

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The Ds\Set::sum function calculates the sum of all the set’s elements.

Syntax

The Ds\Set::sum function can be declared as follows:

public Ds\Set::sum ( ) : int|float

Parameter

The Ds\Set::sum function has no input parameters.

Return value

The Ds\Set::sum function returns the sum of all the set’s elements.

Example

The code snippet below demonstrates the use of the Ds\Set::sum function:

<?php
$set1 = new \Ds\Set([0, 5, 10, 20]);
echo("Sum of all elements of set1 = ");
print_r($set1->sum());
?>
Using the Ds\Set sum() function in PHP

Explanation

  • Line 3: We declare a set set1.
  • Line 6: We use the Ds\Set::sum function to return the sum of elements of set1.

RELATED TAGS

php
sum
communitycreator

CONTRIBUTOR

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring