Php variable type program code explanation

Source: Internet
Author: User
The method for checking the variable type in php is very simple. you can use the gettype () function to return the current variable type. next I will introduce you to the gettype function to check the variable type in detail, for more information, see. stringg... the method for checking the variable type in php is very simple. you can use the gettype () function to return the current variable type. next I will introduce you to the gettype function to check the variable type in detail, for more information, see.

String gettype (mixed $ var) returns the PHP variable type var.

The instance code is as follows:

 

The official saying: do not use gettype () to test a type, because the returned string may need to be changed in future versions. in addition, because it contains a string comparison, it runs slowly.

Use the is _ * function instead of the. instance code as follows:

 

Other variable types

Array_key_exists (mixed key, array search): // check whether the given key name or index exists in the array to determine the data type is_numeric (mixed var ): // check whether the measurement variable is a digital or digital string is_bool ($ var): // check whether the measurement variable is a Boolean is_float ($ var ): // check whether the measurement variable is floating point or is_double or is_real (). is_int ($ var): // check whether the measurement variable is an integer () in the same usage, is_string ($ var): // checks whether the variable is a string is_object ($ var): // checks whether the variable is an object is_array ($ var ): // check whether the measurement variable is an array is_null ($ var): // check whether the measurement variable is null.


Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

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.