Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert numeric strings into numeric types in php

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

This article mainly introduces the php how to convert digital strings into digital types of related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe you will have something to gain after reading this php article on how to convert digital strings into digital types, let's take a look.

Conversion method: 1, use intval () function, syntax "intval ($str)"; 2, use floatval () function, syntax "floatval ($str)"; 3, use settype () function, syntax "settype ($str," float ")".

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

Convert numeric strings to numeric types in php

Method 1: use the intval () function to convert to an integer type

Intval (): used to get the integer value of a variable

Method 2: use the floatval () function to convert to a floating-point type

Floatval (): used to get the floating-point value of a variable

Method 3: use the settype () function to convert to an integer or floating point type

The settype ($var,$type) function sets the variable $var to the specified data type $type.

Example:

The value of $type can be:

"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)

The settype () function changes the original variable.

This is the end of the article on "how to convert numeric strings into digital types in php". Thank you for reading! I believe you all have a certain understanding of "how to convert digital strings into digital types in php". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Numbers types functions characters strings variables methods floating point knowledge grammar content integers articles lieutenant general value simple operation tutorials numerical values data articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Tech Info Docker Redmi Linux