Home > Backend Development > PHP Problem > How to force conversion of data types in php

How to force conversion of data types in php

王林
Release: 2023-03-04 13:18:02
Original
3100 people have browsed it

How to force conversion of data types in php: Add the target type enclosed in parentheses before the variable to be converted to complete the forced type conversion, such as: [(int), (integer)] converted to Integer type; [(string)] is converted into a string.

How to force conversion of data types in php

In PHP, the forced type conversion can be completed by adding the target type enclosed in parentheses before the variable to be converted.

(Recommended tutorial: php graphic tutorial)

  • (int),(integer) Convert to integer type

  • (bool),(boolean) Convert to Boolean type

  • (float),(double),(real) Convert to floating point type

  • (string) Convert to string

  • (array) Convert to array

  • (object) Convert to object

(Video tutorial recommendation: php video tutorial)

Example:

<?php
var_dump((bool) ""); // bool(false)
var_dump((bool) 1); // bool(true)
var_dump((bool) -2); // bool(true)
var_dump((bool) "foo"); // bool(true)
var_dump((bool) 2.3e5); // bool(true)
var_dump((bool) array(12)); // bool(true)
var_dump((bool) array()); // bool(false)
var_dump((bool) "false"); // bool(true)
?>
Copy after login

The above is the detailed content of How to force conversion of data types in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template