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 php casts strings to other types

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

Share

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

This article focuses on "how php converts strings to other types". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "php how to cast strings to other types"!

Cast method: 1, add the target type enclosed in parentheses before the string variable, such as "(int) $str", "(bool) $str", "(float) $str"; 2, use the conversion functions intval (), floatval (), boolval (), settype ().

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

Php casts strings to other types

Method 1: add the target type enclosed in parentheses before the string variable

(int), (integer): convert to integer

(bool), (boolean): convert to Boolean type

(float), (double), (real): convert to floating point type

(array): converting to an array type

(object): converts to an object type.

Example:

2. Use a cast function

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

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

Boolval (): used to get the Boolean value of the variable

Settype (): used to set the variable to the specified type (the settype () function changes the original type of the variable).

Note: the value of the second parameter (the set type) of the settype () function 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)

At this point, I believe you have a deeper understanding of "php how to cast strings to other types". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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