Home > Backend Development > PHP Problem > How to use is_numeric() in PHP to determine whether a variable is a number or a numeric string

How to use is_numeric() in PHP to determine whether a variable is a number or a numeric string

autoload
Release: 2023-03-09 11:24:01
Original
2831 people have browsed it

How to use is_numeric() in PHP to determine whether a variable is a number or a numeric string

In the daily use of PHP, we often need to determine whether a variable is a number or a string of numbers. PHP provides us with a built-in Function is_numeric() helps us determine whether a variable is a number or a numeric string more efficiently.

Syntax:

bool is_numeric ( mixed $var )
Copy after login
  • $var: Variables that need to be judged

  • Return value: TRUE is returned if $var is a number or numeric string, otherwise FALSE is returned.

Usage example:

<?php
$var = array(666678,"a678","666678",null,+125689.66);

foreach ($var as $key => $value) {
    
    if(is_numeric($value)){

    print("参数是数字或数字字符串<br/>");
    }else{

    print("参数不是数字或数字字符串<br/>");
    }
}
?>
Copy after login
输出:
参数是数字或数字字符串
参数不是数字或数字字符串
参数是数字或数字字符串
参数不是数字或数字字符串
参数是数字或数字字符串
Copy after login

Recommended: 2021 PHP Interview Summary of questions (collection)》《php video tutorial

The above is the detailed content of How to use is_numeric() in PHP to determine whether a variable is a number or a numeric string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template