Get the App
SLTechnology News&Howtos  ›  Development  › 

How php forcefully converts strings to int types

Shulou Source: shulou.com Published: 2022-06-01 19:55:49 09月28日 Update

This article introduces how php forcefully converts strings into int types. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Php strong string into int type methods: 1, the use of intval () function, you can get the integer value of the variable, syntax "intval (string variable)"; 2, using settype (), you can set the variable to the specified type, syntax "settype (string variable," integer ")".

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

Method 2: use the intval () function

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

Description: 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.

Method 3: use the settype () function

"boolean" (or "bool", starting with PHP 4.2.0)

"integer" (or "int", starting with PHP 4.2.0)

"float" (available only after PHP 4.2.0, "double" used in older versions is now disabled)

"string"

"array"

"object"

"null" (since PHP 4.2.0)

Example:

Description:

The settype () function changes the type of the variable itself.

So much for sharing about how php forcibly converts strings to int types. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Variables types functions characters strings numeric values methods content more syntax can be help good interest decimal boys buddies tutorials articles versions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Microsoft Xiaomi NVidia