note 84515 modified in function.abs by danbrown

From: Date: Thu, 17 Jul 2008 14:14:03 +0000
Subject: note 84515 modified in function.abs by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141623@lists.php.net to get a copy of this message
[*EDIT* by danbrown AT php DOT net: Merged user's corrected code with previous post content.] jeremys indicated one thing - there is no sgn function wich actually seems a bit strange for me. Of course it is as simple as possible, but it is usefull and it is a standard math function needed occasionally. Well, I have solved this function in a bit different matter: <?php function sgn($liczba) { if($liczba>0) $liczba=1; else if($liczba<0) $liczba=-1; else if(!is_numeric($liczba)) $liczba=null; else $liczba=0; return $liczba; } ?> The difference is that it returns null when the argument isn't a number at all. --was-- I have checked my sgn function and it appears to have some mistakes. Here is corrected version. Any better ideas? <?php function sgn($liczba) { if($liczba>0) $liczba=1; else if($liczba<0) $liczba=-1; else if(!is_numeric($liczba)) $liczba=null; else $liczba=0; return $liczba; } ?> http://php.net/manual/en/function.abs.php

« previous php.notes (#141623) next »