Guest User

Untitled

a guest
Jan 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. <?php
  2.  
  3. class Calc
  4. {
  5.  
  6. private $nums;
  7.  
  8. public function __construct(array $nums)
  9. {
  10. if (!is_array($nums)) {
  11. thown new \Exception("Method wait array");
  12. }
  13.  
  14. $this->nums = $nums;
  15. }
  16.  
  17. public function getResult()
  18. {
  19. $result = 0;
  20. foreach ($this->nums as $num) {
  21. $result += $num;
  22. }
  23.  
  24. return $result;
  25. }
  26.  
  27. }
Add Comment
Please, Sign In to add comment