note 129234 added to function.is-numeric

From: Date: Sat, 10 Feb 2024 17:30:51 +0000
Subject: note 129234 added to function.is-numeric
Groups: php.notes 
Request: Send a blank email to php-notes+get-221188@lists.php.net to get a copy of this message
It may be obvious to some, but since it's not spelled out in the documentation: a negative number does not count as a number (i.e. returns false). The way I've solved this in the past is to test the string multiplying by -1 if there is any possibility that the 'number' could be negative --works given an input of '1234' or '-1234' function testNumber($number) { if (is_numeric($number)||is_numeric($number*-1)) { //yourcode } } ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.131 (proxied: 176.100.43.209) ---- Manual Page -- https://php.net/manual/en/function.is-numeric.php Edit -- https://main.php.net/note/edit/129234 Del: integrated -- https://main.php.net/note/delete/129234/integrated Del: useless -- https://main.php.net/note/delete/129234/useless Del: bad code -- https://main.php.net/note/delete/129234/bad+code Del: spam -- https://main.php.net/note/delete/129234/spam Del: non-english -- https://main.php.net/note/delete/129234/non-english Del: in docs -- https://main.php.net/note/delete/129234/in+docs Del: other reasons-- https://main.php.net/note/delete/129234 Reject -- https://main.php.net/note/reject/129234 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221188) next »