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

慕斯
Release: 2023-04-10 06:24:02
Original
4494 people have browsed it

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);
?>
Copy after login

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);
?>
Copy after login

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));
?>
Copy after login

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!

Related labels:
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!