note 89530 deleted from function.func-get-args by peehaa
| From: | peehaa@php.net | Date: | Mon, 08 Apr 2019 06:11:38 +0000 |
| Subject: | note 89530 deleted from function.func-get-args by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210549@lists.php.net to get a copy of this message | ||
Note Submitter: Oto Brglez
----
How to create simple sum function that can sum N arguments. Like this:
<?php
function sum(){
$s=0;
foreach(func_get_args() as $a) $s+= is_numeric($a)?$a:0;
return $s;
};
print sum(1,2,3,4,5,6); // will return 21
print sum(3,2,1); // will return 6
print sum(false,array(),5,5); // will return 10
?>