Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use intval () in php

Shulou Source: shulou.com Published: 2022-06-03 16:49:20 09月13日 Update

This article mainly shows you "how to use intval () in php". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to use intval () in php".

In php, the intval () function can get the integer value of a variable, which is often used for data type conversion, converting a variable of type string to an integer type; the syntax is "intval ($var [, $base])".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The intval () function is used to get the integer value of a variable. Syntax format:

Int intval (mixed $var [, int $base = 10])

$var: the numerical value to be converted to integer.

$base: the base used for conversion.

If base is 0, determine which binary to use by examining the format of the var:

Use hexadecimal (hex) if the string includes the prefix of "0x" (or "0X"); otherwise

Use octal (octal) if the string starts with "0"; otherwise

Decimal (decimal) will be used.

The intval () function is often used for data type conversions, converting variables of string type to integer types.

The intval () function returns the integer value of the variable var by using the specified binary base conversion (the default is decimal). Intval () cannot be used for object, otherwise an E_NOTICE error will be generated and 1 will be returned.

Example: convert a string to an integer

Output result:

The above is all the content of the article "how to use intval () in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Type variable base character string function content numeric integer article data format grammar study help prefix decimal tutorial quantity easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Xiaomi Microsoft MySQL macOS