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.