A brief discussion on the example code of the data type judgment function of variables in PHP

黄舟
Release: 2023-03-06 11:44:01
Original
1481 people have browsed it

The following editor will bring you a brief discussion of the data type judgment function of variables in PHP. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

In php, we can print out the type and value of variables through var_dump(). At the same time, we can determine the type of variables through some functions. If you just want to get the data type of a variable, you can use the gettype() function. gettype($t) returns a string of the data type of $t. If $t does not belong to the 8 basic variable types in PHP, it returns "unknown type". We can also directly determine whether it is a type type function through the is_type series function. If so, it will return true, not false.

For example:


is_bool() Whether it is a Boolean type
is_int() Whether it is an integer type
is_float () Whether it is a floating point type
is_string() Whether it is a string type
is_array() Whether it is an array type
is_object() Whether it is an object type
is_resource() Whether it is a resource type
is_null() Whether it is empty
is_scalar() Whether it is a scalar type, that is, an integer floating point Boolean type or a string type.
is_numeric() Whether it is any type of number or numeric string
is_callable() Whether it is a valid function name

The above is a brief discussion of the data type judgment function example code of variables in PHP. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!