PHP determines whether a number is an integer

王林
Release: 2023-03-10 17:56:02
Original
3299 people have browsed it

The way PHP determines whether a number is an integer is to use the is_int function to determine and use the number to be determined as a parameter, such as [is_int($var_name1)].

PHP determines whether a number is an integer

The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.

To determine whether a number is an integer is very simple in PHP. PHP has a very rich set of functions, including the is_int function, through which we can easily determine whether a number is an integer.

Let’s introduce the is_int function.

is_int() function is used to detect whether a variable is an integer. TRUE if the specified variable is an integer, FALSE otherwise.

Sample code:

<?php
$var_name1 = 678;
$var_name2 = "a678";
$var_name3 = "678";
$var_name4 = 999;
$var_name5 = 698.99;
$var_name6 = array("a1", "a2");
$var_name7 = + 125689.66;
if (is_int($var_name1)) {
    echo "$var_name1 是整数" . PHP_EOL;
} else {
    echo "$var_name1 不是整数" . PHP_EOL;
}
if (is_int($var_name2)) {
    echo "$var_name2 是整数" . PHP_EOL;
} else {
    echo "$var_name2 不是整数" . PHP_EOL;
}
$result = is_int($var_name3);
echo "[ $var_name3 是整数吗? ]" . var_dump($result) . PHP_EOL;
$result = is_int($var_name4);
echo "[ $var_name4 是整数吗? ]" . var_dump($result) . PHP_EOL;
$result = is_int($var_name5);
echo "[ $var_name5 是整数吗? ]" . var_dump($result) . PHP_EOL;
$result = is_int($var_name6);
echo "[ $var_name6 是整数吗? ]" . var_dump($result) . PHP_EOL;
$result = is_int($var_name7);
echo "[ $var_name7 是整数吗? ]" . var_dump($result);
?>
Copy after login

Let’s take a look at the output:

PHP determines whether a number is an integer

##Related recommendations:

php video tutorial

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

Related labels:
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!