How to convert int in php: 1. Create a PHP sample file; 2. Determine the value to be converted; 3. Use the "(int)" or "(integer)" method to force conversion, the syntax is as follows "var_dump((int) "221");echo "
";var_dump((integer)"-25"".
This tutorial operation Environment: Windows 7 system, PHP version 8.1, Dell G3 computer.
php How to convert int?
php int type conversion
int is a collection ℤ = a number in {…, -2, -1, 0, 1, 2, …}.
To convert a value to int,
Use (int) or (integer) cast.
However, in most cases no cast is required, because when an operator, function or flow control requires an int parameter, the value is automatically converted. You can also use the function intval() To convert a value to int type.
intval() syntax
intval(mixed $value, int $base = 10): int
Parameters
value
The quantity value to be converted to integer
base
The hexadecimal system used for conversion
<?php var_dump( (int) "221" // int(221) ); echo "<br>"; var_dump( (integer)"-25" //int(-25) ); echo "<br>"; echo intval(42); // 42 echo "<br>"; echo intval(4.2); // 4 echo "<br>"; echo intval('42'); // 42 echo "<br>"; echo intval('+42'); // 42 echo "<br>"; echo intval('-42'); // -42 echo "<br>"; echo intval(042); // 34 echo "<br>"; echo intval('042'); // 42 echo "<br>"; echo intval(2e2); // 200 e后面表示添加几个0 echo "<br>"; echo intval('1e10'); // 1 echo "<br>"; echo intval(0x1A); // 26 0x开头是16进制 echo "<br>"; echo intval(42000000); // 42000000 echo "<br>"; echo intval(420000000000000000000); // -4275113695319687168 echo "<br>"; echo intval('420000000000000000000'); // 9223372036854775807 echo "<br>"; echo intval(42, 8); // 42 echo "<br>"; echo intval('42', 8); // 34 echo "<br>"; echo intval(array()); // 0 echo "<br>"; echo intval(array('foo', 'bar')); // 1 echo "<br>"; echo intval(false); // 0 echo intval(true); // 1 ?>
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to convert int in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
