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

PHP determines whether a string is a number

藏色散人
Release: 2023-02-26 08:24:01
Original
4257 people have browsed it

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 )
Copy after login

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 ;
}
Copy after login

Output:

678 是数字
Copy after login

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!

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template