PHP determines whether it is a number

(*-*)浩
Release: 2023-02-25 11:10:02
Original
5507 people have browsed it

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

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!