Two methods for php to determine whether it is an integer-PHP source code

Source: Internet
Author: User
Php checks whether a number is an integer in two ways. php checks whether a number is an integer during the interview. I have written two methods, but I don't know whether there are any other methods.


Method 1: Use the php built-in function is_int () to easily determine whether the number is an integer.


Method 2: You can use four homes or five to enter the number and compare it with the original number. for example, the result of floor (3.1) is 3. Obviously, 3! = 3.1, or use the ceil () function to determine whether it is an integer.


Example:


$ A = 3.3;

// Method 1

If (is_int ($ )){

Echo "$ a is an integer! ";

} Else {

Echo "$ a is not an integer! ";

}

// Method 2

If (floor ($ a) ==$ ){

Echo "$ a is an integer! ";

} Else {

Echo "$ a is not an integer! ";

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.