Skip to content

Instantly share code, notes, and snippets.

@tbreuss
Created April 10, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbreuss/10413560 to your computer and use it in GitHub Desktop.
Save tbreuss/10413560 to your computer and use it in GitHub Desktop.
A simple function to recognize whether the value is a natural number.
<?php
function is_natural($val, $acceptzero = false)
{
$return = ((string) $val === (string) (int) $val);
if ($acceptzero) {
$base = 0;
} else {
$base = 1;
}
if ($return && intval($val) < $base) {
$return = false;
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment