Home  >  Article  >  Backend Development  >  How to use PHP data types to view and determine data types

How to use PHP data types to view and determine data types

慕斯
慕斯Original
2021-05-21 16:24:224442browse

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! ! !

How to use PHP data types to view and determine data types

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:

How to use PHP data types to view and determine data types

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:

How to use PHP data types to view and determine data types

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:

How to use PHP data types to view and determine data types

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!

Statement:
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