วันพุธที่ 30 เมษายน พ.ศ. 2557

09:51

ฟังก์ชัน is_numeric()
check ตัวแปรว่าเป็นตัวเลขหรือสตริงตัวเลข หรือไม่ด้วยฟังก์ชัน is_numeric()





ตัวอย่าง
<?php

$a="1000";
$b=1000;
$c="10.36";
$d=10.36;
$e="r10";
if ( is_numeric($a) ) echo "variable a is numeric";
else echo "variable a is not numeric";
echo "<br>";
if ( is_numeric($b) ) echo "variable b is numeric";
else echo "variable b is not numeric";
echo "<br>";
if ( is_numeric($c) ) echo "variable c is numeric";
else echo "variable c is not numeric";
echo "<br>";
if ( is_numeric($d) ) echo "variable d is numeric";
else echo "variable d is not numeric";
echo "<br>";
if ( is_numeric($e) ) echo "variable e is numeric";
else echo "variable e is not numeric";

?>
ฟังก์ชัน is_numeric() จะ return ค่า TRUE ถ้าตัวแปรเป็นตัวเลขหรือสตริงตัวเลข
FALSE ถ้าตัวแปรไม่ใช่ตัวเลขหรือสตริงตัวเลข

0 ความคิดเห็น:

แสดงความคิดเห็น

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.