PHP settype() function 您所在的位置:网站首页 三菱电机空调与三菱重工空调有什么区别 PHP settype() function

PHP settype() function

#PHP settype() function| 来源: 网络整理| 查看: 265

Next »229/627« PreviousPHP settype() function

In this chapter you will learn:

Description for PHP settype() functionSyntax for PHP settype() functionParameter for PHP settype() functionReturn value for PHP settype() functionExample - Set the typeDescription

We can use PHP's settype() function to change the type of a variable while preserving the variable's value.

Syntaxbool settype ( mixed &$var , string $type )Parameter ParameterMeaning varThe variable being converted. typenew type

Possibles values of type are:

"boolean" or "bool" "integer" or "int" "float" "string" "array" "object" "null" Return

Returns TRUE on success or FALSE on failure.

Example

At first $test_var variable contains 1.23, a floating - point value.

Next, $test_var is converted to a string, which means that the number 1.23 is now stored using the characters 8, . , 2 , and 3.

After converting $test_var to an integer type, it contains the value 8; the fractional part of the number has been lost.

Finally, after converting $test_var to a Boolean, it contains the value true (which PHP displays as 1 ). This is because PHP converts a non - zero number to the Boolean value true.

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

Description for PHP strval() functionSyntax for PHP strval() functionParameter for PHP strval() functionReturn value for PHP strval() functionExample - Convert class to a string Next »« Previous


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有