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

PHP determines whether it is a number

(*-*)浩
(*-*)浩Original
2019-09-28 09:52:025577browse

PHP determines whether it is a number

PHP is_numeric Detects whether a variable is a number or a numeric string (Recommended learning: PHP Programming from Beginner to Master)

bool is_numeric ( mixed $var )

Returns TRUE if var is a number or numeric string, otherwise returns FALSE.

Recommended manual:php complete self-study manual

For example 1:

<?php
    $v = is_numeric (&#39;58635272821786587286382824657568871098287278276543219876543&#39;) ? true : false;
    
    var_dump ($v);
?>

The above script will output:

bool(true)
Recommended related articles:
1.php determines whether a string is a number
2.How does php determine how many digits a number has?
3.php determines whether it is an integer
##Related video recommendations:1.
Dugu Jiujian (4)_PHP video tutorial

For example 2:

<?php
$str="0";
$strTest=is_numeric(0);
var_dump($strTest);
?>
boolean true
//
function int_str($str){
    if(is_numeric($str)){
        $str = &#39;m&#39;.$str;
    }
    return $str;
}

The above is the detailed content of PHP determines whether it 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