Get the App
SLTechnology News&Howtos  ›  Development  › 

How to view and judge PHP data types

Shulou Source: shulou.com Published: 2022-06-03 05:17:18 10月03日 Update

This article mainly shows you "how to view and judge PHP data type", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to view and judge PHP data type" this article.

Viewing and judging of PHP data types viewing data types

In learning, we can carry out different operations according to different data types, so how to view a data type is particularly important. We know the type of a data before we can proceed to the next step. Next, I'll introduce you to two functions that view data types.

Gettype (passing in a variable) can get the type of variable

If you pass in a declared variable in gettype, you can pass out the variable type of that variable, as an example:

Output result:

Thus, gettypt () can get the variable type of the variable, but it needs to be displayed by echo, so is there a function that can directly output the variable type?

Var_dump (passing in a variable) outputs variants and values

Var_dump can output not only the variable type of the variable, but also the value of the variable. Examples are as follows:

Output result:

Thus, var_dump () can directly output not only the variable type of the variable, but also the value of the variable.

Determine the data type

In daily use and learning, we should not only look at the data types of variables, but also be able to judge. There are not many data types of variables, and it is very simple to judge, so you need to use a series of is_* functions.

It is called a series function because it does not exist alone, and since you want to determine whether something is a type or not, it often appears with the type of variable that needs to be judged.

If this type returns true, not this type returns false.

Whether is_bool () is Boolean

If the variable is Boolean, the return result is true and the output true interval; if the variable is not Boolean, the return result is false and the output false interval.

Output result:

The output is: study hard. The output true interval, the return result is true, the variable is Boolean.

Whether is_null is empty

If the variable is empty, the return result is true and the output true interval; if the variable is not empty, the return result is false and the output false interval.

Tags: Type variable output data result interval learning function Boolean content article different thus help important next thing two the reason Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MySQL Apple NVidia Xiaomi