A simple variable-related question

Source: Internet
Author: User
A simple variable question & lt ;? Php $ d = & quot; 123.45 & quot; $ e = settype ($ d, float); echo & quot; $ d & lt; br & gt; & quot ;; var_dump ($ d); echo & quot; & lt; br & a simple variable problem
USD d = "123.45 ";
$ E = settype ($ d, float );
Echo "$ d
";
Var_dump ($ d );
Echo"
$ E
";
Var_dump ($ e );
Echo"

";
?>

Why is Output $ e 1? No,

------ Solution --------------------
$ E is the execution result of settype. if the result is successful, the value is true, and the value is 1.

Settype ($ d, "float"); this is better
------ Solution --------------------
Floating point, so var_dump ($ d); isn't the print result float? Before execution, the string type
The execution result is still saved in $ d.

$ E is the execution result of the settype function. the execution succeeds or fails, so var_dump ($ e); the result is Boolean.
------ Solution --------------------
You have to look at the returned results of the function. you can't just imagine it by yourself...

This function returns TRUE or FALSE to let you know whether the execution is successful, instead of returning the set function type...
------ Solution --------------------
Settype -- set the variable type
Description
Bool settype (mixed var, string type)


Set the var variable type to type.

The possible value of type is:


"Boolean" (or "bool", starting from PHP 4.2.0)

"Integer" (or "int", starting from PHP 4.2.0)

"Float" (only available after PHP 4.2.0, and "double" used in earlier versions is disabled now)

"String"

"Array"

"Object"

"Null" (from PHP 4.2.0)


If the call succeeds, TRUE is returned. if the call fails, FALSE is returned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.