Return to Snippet

Revision: 3011
at May 23, 2007 10:50 by jgeewax


Initial Code
/**
 * Check if a number is a counting number by checking if it
 * is an integer primitive type, or if the string represents
 * an integer as a string
 */
function is_int_val($data) {
	if (is_int($data) === true) return true;
	elseif (is_string($data) === true && is_numeric($data) === true) {
		return (strpos($data, '.') === false);
	} 
	return false;
}

Initial URL

                                

Initial Description
PHP has is_numeric, and is_int, but this is a not a complete set. Is_numeric doesn't maintain that the value is strictly an integer, and is_int 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.

Initial Title
Check if integer _value_

Initial Tags

                                

Initial Language
PHP