note 109217 added to function.is-int

From: Date: Wed, 27 Jun 2012 09:24:09 +0000
Subject: note 109217 added to function.is-int
Groups: php.notes 
Request: Send a blank email to php-notes+get-188910@lists.php.net to get a copy of this message
Just a shorter way to check if your variable is an int or a string containing a int without others digit than 0 to 9 : <?php $bool = ( !is_int($value) ? (ctype_digit($value)) : true ); $value = 42; //true $value = '42'; //true $value = '1e9'; //false $value = '0155'; //true $value = 0155; //true $value = 0xFF; //true while it's just the same as 255 $value = '0xFF'; //false $value = 'a'; //false $value = array(); //false $value = array('5'); //false $value = array(5); false $value = ''; //false $value = NULL; //false ?> Short & cool :) ---- Server IP: 89.31.146.176 Probable Submitter: 62.244.76.155 ---- Manual Page -- http://www.php.net/manual/en/function.is-int.php Edit -- https://master.php.net/note/edit/109217 Del: integrated -- https://master.php.net/note/delete/109217/integrated Del: useless -- https://master.php.net/note/delete/109217/useless Del: bad code -- https://master.php.net/note/delete/109217/bad+code Del: spam -- https://master.php.net/note/delete/109217/spam Del: non-english -- https://master.php.net/note/delete/109217/non-english Del: in docs -- https://master.php.net/note/delete/109217/in+docs Del: other reasons-- https://master.php.net/note/delete/109217 Reject -- https://master.php.net/note/reject/109217 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188910) next »