Several methods for detecting data types in PHP (Summary) and several methods for data types

Source: Internet
Author: User

Several methods for detecting data types in PHP (Summary) and several methods for data types

In JavaScript, typeof can be used to detect basic data types, and instanceof can be used to detect referenced data types. In PHP, there are also methods for detecting data types, as shown below:

1. gettype)

<? Php $ arry = array ('A', 'B', 'C'); echo gettype ($ arry); // array?>

2. Data type, quantity, and content of the output variable (var_dump)

View Source code printing Code help

<? Php $ str = 'Hello world'; var_dump ($ str); // string (11) "hello world"?>

3. check whether a variable is of the specified data type (is_array, is_string, is_int, is_double, etc.). If it is true, return 1. If it is false, return null.

View Source code printing Code help

<? Php $ num = 123; if (is_array ($ num) {echo 'This is an array';} else if (is_string ($ num )) {echo 'This is a string';} else if (is_int ($ num) {echo 'This is an integer';} else if (is_double ($ num )) {echo 'this is a floating point number ';}?>

Maybe your friend is looking for the answer to this question. Please share it with him!

The above several methods for detecting data types in PHP (Summary) are all the content that I have shared with you. I hope you can give us a reference and support for the help house.

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.