is_numeric คือ คำสั่งสำหรับการตรวจสอบค่าของตัวแปรว่าเป็นข้อมูลชนิดตัวเลขหรือเปล่าของภาษา PHP
ตัวอย่างโปรแกรม
<?
$data = array(
"99",
2222,
0x53DF9,
"Amplysoft",
"Hello",
"not numeric",
array(),
9.52,
"1523.369"
);
foreach ($data as $value) {
if ( is_numeric($value) ) {
echo "'{$value}' is numeric";
} else {
echo "'{$value}' is NOT numeric";
}
echo "<br/>";
}
?>
ผลลัพธ์
'99' is numeric
'2222' is numeric
'343545' is numeric
'Amplysoft' is NOT numeric
'Hello' is NOT numeric
'not numeric' is NOT numeric
'Array' is NOT numeric
'9.52' is numeric
'1523.369' is numeric