Posted By

jgeewax on 05/23/07


Tagged

check Value integer


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
spivurno


Check if integer _value_


 / Published in: PHP
 

PHP has isnumeric, and isint, but this is a not a complete set. Isnumeric doesn't maintain that the value is strictly an integer, and isint returns true if the TYPE of the variable is an integer. This returns whether a variable holds an integer value as either a true int, or as a string.

  1. /**
  2.  * Check if a number is a counting number by checking if it
  3.  * is an integer primitive type, or if the string represents
  4.  * an integer as a string
  5.  */
  6. function is_int_val($data) {
  7. if (is_int($data) === true) return true;
  8. elseif (is_string($data) === true && is_numeric($data) === true) {
  9. return (strpos($data, '.') === false);
  10. }
  11. return false;
  12. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: spivurno on January 25, 2010

Used. Thanks for sharing.

You need to login to post a comment.