php adalah variabel angka
if(is_numeric($what_am_i)){
//true
}
Poised Penguin
if(is_numeric($what_am_i)){
//true
}
// Check if variable is int
$id = "1";
if(!intval($id)){
throw new Exception("Not Int", 404);
}
else{
// this variable is int
}
<?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';
}
?>
$a = 5; //returns true
$a = "5"; //returns false
$a = 5.3; //returns false
is_int($a);
<?php
$values = array(23, "23", 23.5, "23.5", null, true, false);
foreach ($values as $value) {
echo "is_int(";
var_export($value);
echo ") = ";
var_dump(is_int($value));
}
?>
/* Output
is_int(23) = bool(true)
is_int('23') = bool(false)
is_int(23.5) = bool(false)
is_int('23.5') = bool(false)
is_int(NULL) = bool(false)
is_int(true) = bool(false)
is_int(false) = bool(false)
*/
is_int(mixed $value): bool