php numeric乘法,PHP is_numeric()用法及代码示例
is_numeric()函數是PHP中的內置函數,用于檢查傳入函數中作為參數的變量是數字還是數字字符串。該函數返回一個布爾值。
用法:
bool is_numeric ( $var )
參數:該函數接受一個必須的單個參數,如下所述:
$var:此輸入參數是變量,函數將檢查該變量是數字還是數字字符串。基于此驗證,該函數返回布爾值。
返回值:如果$var是數字或數字字符串,則該函數返回TRUE,否則返回FALSE。
例子:
Input : $var = 12
Output : True
Input : $var = "Geeks for Geeks"
Output : False
以下示例程序旨在說明is_numeric()函數:
程序1:在此程序中,將數字作為輸入傳遞。
$num = 12;
if (is_numeric($num)) {
echo $num . " is numeric";
}
else {
echo $num . " is not numeric";
}
?>
輸出:
12 is numeric
程序2:在此程序中,將字符串作為輸入傳遞。
$element = "Geeks for Geeks";
if (is_numeric($element)) {
echo $element . " is numeric";
}
else {
echo $element . " is not numeric";
}
?>
輸出:
Geeks for Geeks is not numeric
程序3:在此程序中,將數字字符串作為輸入傳遞。
$num = "467291";
if (is_numeric($num)) {
echo $num . " is numeric";
}
else {
echo $num . " is not numeric";
}
?>
輸出:
467291 is numeric
程序4:
$array = array(
"21/06/2018",
4743,
0x381,
01641,
0b1010010011,
"Geek Classes"
);
foreach ($array as $i) {
if (is_numeric($i)) {
echo $i . " is numeric"."\n";
} else {
echo $i . " is NOT numeric"."\n";
}
}
?>
輸出:
21/06/2018 is NOT numeric
4743 is numeric
897 is numeric
929 is numeric
659 is numeric
Geek Classes is NOT numeric
總結
以上是生活随笔為你收集整理的php numeric乘法,PHP is_numeric()用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电信营业厅怎么改套餐(中国电信网上营业厅
- 下一篇: 微店app怎么卖东西(汉典微字的基本解释