note 84860 added to function.abs

From: Date: Sat, 02 Aug 2008 04:58:36 +0000
Subject: note 84860 added to function.abs
Groups: php.notes 
Request: Send a blank email to php-notes+get-143048@lists.php.net to get a copy of this message
This is a note to concordia's comment at http://us.php.net/manual/en/function.abs.php#58508 I believe there is an easier way to turn a positive number into a negative one and vice versa in one line: <?php function change_pol($integer){ return (0 - $integer); } ?> It takes another additional line to check if it's really a number: <?php function change_pol($integer){ if(!is_numeric($integer)){ return false; } return (0 - $integer); } ?> Keep in mind that if I do 0 - -5 (given that $integer is -5), it will turn into +, thus turning the result into +5. Works like a charm for me. Input like '-5' will work as well (as PHP turns it automatically into a string or float), even '-.9' will return as 0.9 . ---- Server IP: 208.69.120.35 Probable Submitter: 66.91.94.7 ---- Manual Page -- http://www.php.net/manual/en/function.abs.php Edit -- https://master.php.net/note/edit/84860 Del: integrated -- https://master.php.net/note/delete/84860/integrated Del: useless -- https://master.php.net/note/delete/84860/useless Del: bad code -- https://master.php.net/note/delete/84860/bad+code Del: spam -- https://master.php.net/note/delete/84860/spam Del: non-english -- https://master.php.net/note/delete/84860/non-english Del: in docs -- https://master.php.net/note/delete/84860/in+docs Del: other reasons-- https://master.php.net/note/delete/84860 Reject -- https://master.php.net/note/reject/84860 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143048) next »