Example of function usage for determining numbers, characters, and objects in php

Source: Internet
Author: User
This article mainly introduces the usage of the number, character, and object judgment function in php, and analyzes is_bool (), is_int (), is_integer (), is_float (), is_real () in the form of an example () functions such as is_object () and is_array () and their specific usage. if you need them, you can refer to the example in this article to describe the usage of php's number, character, and object judgment functions. Share it with you for your reference. The specific analysis is as follows:

In php, numbers, characters, objects, arrays, and so on can be viewed as is_bool (), is_int (), is_integer (), is_float (), is_real (), and is_object () and is_array (). How much do you know.

1. double-precision number judgment: is_double

Is_double -- is_float () alias

Description: This function is an alias for is_float (). The code is as follows:

The code is as follows:

$ Temperature = 15.23;
If (is_double ($ Temperature ))
{
Print ("Temperature is a double "."
");
}


2. integer judgment: alias of is_integer -- is_int () and is_long ()

Description: This function is an alias for is_int (). The code is as follows:

The code is as follows:

$ PageCount = 2234;
If (is_integer ($ PageCount ))
{
Print ("$ PageCount is an integer "."
");
}


3. object judgment: is_object -- checks whether the variable is an object.

Description: bool is_object (mixed var)

If var is an object, TRUE is returned; otherwise, FALSE is returned. the code is as follows:

The code is as follows:

Class widget
{
Var $ name;
Var $ length;
}
$ Thing = new widget;
If (is_object ($ thing ))
{
Print ("thing is an object "."
");
}


4. character judgment: is_string -- check whether the variable is a string

Description: bool is_string (mixed var)

If var is a string, TRUE is returned; otherwise, FALSE is returned. the code is as follows:

The code is as follows:

$ Greeting = "www.bitsCN.com ";
If (is_string ($ Greeting ))
{
Print ("Greeting is a string "."
");
}


5. is_numeric -- checks whether the variable is a numeric or numeric string.

Description: bool is_numeric (mixed var)

If var is a numeric or numeric string, TRUE is returned; otherwise, FALSE is returned. the code is as follows:

The code is as follows:

$ Int = 1;
If (is_numeric ($ int ))
{
Print ("This is a real number, man "."
");
}

Here is just a simple description of php Objects, numbers, character judgment functions, the difficulty is relatively simple. I hope this article will help you with PHP programming.

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.