Function for Summation


/ Published in: PHP
Save to your folder(s)

Easy but powerful.


Copy this code and paste it in your HTML
  1. <?php
  2. function sum($from, $to){
  3. if ($from == $to) {
  4. return $from;
  5. }
  6. return $to + sum($from,$to-1);
  7. }
  8.  
  9. echo sum(8,100);
  10. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.