$var_num = "1";
$var_str = "Hello World";
var_dump( is_numeric($var_num), is_numeric($var_str) );
/*
Output -
bool(true)
bool(false)
*/
<?php if (is_numeric(887)) { echo "Yes"; } else { echo "No"; } ?>
<?php
// combination of is_int and type coercion
// FALSE: 0, '0', null, ' 234.6', 234.6
// TRUE: 34185, ' 34185', '234', 2345
$mediaID = 34185;
if( is_int( $mediaID + 0) && ( $mediaID + 0 ) > 0 ){
echo 'isint'.$mediaID;
}else{
echo 'isNOTValidIDint';
}
?>
<?php if (is_numeric("cake")) { echo "Yes"; } else { echo "No"; } ?>
<?php
$strings = array('1820.20', '10002', 'wsl!12');
foreach ($strings as $testcase) {
if (ctype_digit($testcase)) {
echo "The string $testcase consists of all digits.
";
} else {
echo "The string $testcase does not consist of all digits.
";
}
}
?>