How to get the variable type and determine whether it is a variable in PHP _php tutorial

Source: Internet
Author: User
In PHP because variables do not need to be defined in advance, we have a lot of time for the PHP variable type is cheek paste, but PHP gives us the GetType () function to get the variable type, he can judge all the variable types in PHP.

Detecting variable types

GetType ($var)
This function returns the type of the variable. For example, "string", "Integer", "Boolean", "floating-point value", and so on. This function is commonly used to verify that a variable is the type you expect before inserting a variable into a strictly typed database field.

The code is as follows Copy Code

Returns string
$var = "Hello";
Echo GetType ($var);
Returns double
$var = 1000.56;
Echo GetType ($var);
?>

Warning
Do not use GetType () to test for a type, because the string it returns may need to be changed in a future release. In addition, it is slower to run because it contains a comparison of strings.

Use the is_* function instead.


Check for valid variables

Isset is used to determine the existence of a variable, if it is true otherwise return false, this variable is useful to us, we can be used to determine such as a get post, such as whether the variable is in the OH.

Isset instance "

The code is as follows Copy Code

$a = "Test";
$b = "Anothertest";

echo isset ($a)? ' True ': ' false ';

The output is: true

Example 2

The code is as follows Copy Code

Returns True
$var = "Yes";
echo isset ($var)? "True": "false";
Returns false
echo isset ($test)? "True": "false";
?>

The above is two super simple PHP function Isset () and GetType () function is not difficult, there is need to know the friend can refer to.

http://www.bkjia.com/PHPjc/629174.html www.bkjia.com true http://www.bkjia.com/PHPjc/629174.html techarticle In PHP because variables do not need to be defined in advance, we have a lot of time for PHP variable type is cheek paste, but PHP provides us with the GetType () function to get the variable type, he can judge ...

  • Related Article

    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.