Home >Backend Development >PHP Problem >PHP determines whether a string is a number

PHP determines whether a string is a number

藏色散人
藏色散人Original
2019-10-10 16:40:164204browse

PHP determines whether a string is a number

php determines whether a string is a number

is_numeric() function is used to detect whether a variable is a number or a number String.

PHP version requirements: PHP 4, PHP 5, PHP 7

Syntax

bool is_numeric ( mixed $var )

Parameter description:

$var: The variable to be tested.

Return value

Returns TRUE if the specified variable is a number or numeric string, otherwise returns FALSE.

Example:

<?php
$var_name1=678;

if (is_numeric($var_name1))
{
    echo "$var_name1 是数字" . PHP_EOL;
}
else
{
    echo "$var_name1 不是数字" . PHP_EOL ;
}

Output:

678 是数字

For more PH related P knowledge, please visit PHP Chinese website!

The above is the detailed content of PHP determines whether a string is a number. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn