note 34196 added to function.sqrt
| From: | bishop at rack1 dot php dot net | Date: | Fri, 18 Jul 2003 03:09:06 +0000 |
| Subject: | note 34196 added to function.sqrt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52311@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.sqrt.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34196
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34196&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34196&report=yes