note 34196 deleted from function.sqrt by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:36:22 +0000 |
| Subject: | note 34196 deleted from function.sqrt by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189879@lists.php.net to get a copy of this message | ||
Note Submitter: bishop
----
Compute a triangle's area:
function triangleArea($a, $b /* ... */) {
if (func_num_args() === 3) {
$s = .5 * ($a + $b + ($c = func_get_arg(2)));
return sqrt($s * ($s-$a) * ($s-$b) * ($s-$c));
} else {
return (.5 * $a * $b);
}
}
With 2 args, parameters are triangle's base and height. With 3 args, parameters are the
lengths of each side. Argument order is not important.
Either way, you get the area.