If it were you, how would you use PHP data types to view and determine data types? This article will take you into the wonderful space of PHP, follow my footsteps and set off together! ! !
View data type
gettype(pass in a Variable) and so on to obtain the type of the variable
var_dump (pass in a variable) output the type and value of the variable
About gettype data type:
The demo code is as follows:
<?php $x=1.241; echo gettype($x); ?>
The execution result is as shown in the figure:
About var_dump The data type was also mentioned in the previous article.
The demo code is as shown in the figure:
<?php $x=1.241; var_dump($x); ?>
The execution result is as shown in the figure:
Supplement: Knowledge points about data types:
Variables: Integer (int) Float (float) String (string)
Mixed types: array (array) object (object)
Special types: empty (null) resource (resouce) callback (callback)
About judging the data type:
Generally use the is_*
function to determine whether it is a certain type of data. If so, the type returns true, otherwise it is false;
For example:
is_null is empty
is_bool is Boolean
Is is_float a floating point number
Is_array an array
is_object is an object, etc.
The code is demonstrated as follows:
<?php $int =3; var_dump(is_int($int)); ?>
The execution result is as shown in the figure:
Recommended: "PHP Video Tutorial"
The above is the detailed content of How to use PHP data types to view and determine data types. For more information, please follow other related articles on the PHP Chinese website!