Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert numeric strings into numeric types in php

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report