ฟังก์ชัน is_numeric()
ความหมายของฟังก์ชันและการใช้งาน
ตรวจสอบตัวแปรว่าเป็นประเภท string หรือ ตัวเลข หรือไม่ ด้วยฟังก์ชัน is_numeric()
รูปแบบการเขียน (Syntax)
is_numeric($v)
- $v คือ ชื่อตัวแปร
ตัวอย่าง
<?php
$v="1000";
$w=1000;
$x="10.36";
$y=10.36;
$z="r10";
if ( is_numeric($v) ) echo "variable v is numeric";
else echo "variable v is not numeric";
echo "<br>";
if ( is_numeric($w) ) echo "variable w is numeric";
else echo "variable w is not numeric";
echo "<br>";
if ( is_numeric($x) ) echo "variable x is numeric";
else echo "variable x is not numeric";
echo "<br>";
if ( is_numeric($y) ) echo "variable y is numeric";
else echo "variable y is not numeric";
echo "<br>";
if ( is_numeric($z) ) echo "variable z is numeric";
else echo "variable z is not numeric";
?>
ฟังก์ชัน is_numeric() จะ return ค่า TRUE ถ้าเป็นตัวแปรประเภท string หรือ ตัวเลข
ฟังก์ชัน is_numeric() จะ return ค่า FALSE ถ้าไม่เป็นตัวแปรประเภท string หรือ ตัวเลข