猿问

请问我要判断$b 为数值,该怎么判断呢?

$a="a";
$b=0; //或$b=20;
现在我要判断$b 为数值,该怎么判断?

偶然的你
浏览 121回答 3
3回答

梦里花落0921

is_numeric(PHP 4, PHP 5)is_numeric -- Finds whether a variable is a number or a numeric stringDescriptionbool is_numeric ( mixed var )Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.ParametersvarThe variable being evaluated.Return ValuesReturns TRUE if var is a number or a numeric string, FALSE otherwise.See Alsoctype_digit()is_bool()is_null()is_float()is_int()is_string()is_object()is_array()

翻阅古今

$a="a";$b=0; //或$b=20;if(is_numeric($b)){echo "Number";}else{echo "Not Number";}

万千封印

is_numeric($a);是返回为TRUE 不是返回为FALSE
随时随地看视频慕课网APP
我要回答