开发者

settype() converts to bool instead of string

In PHP, the settype() function as below should change the type of $myvar to a string however when I run it it displays as boolean. But If i change $myvar to $my_var settype correctly changes type to string. Why is that so?

<?php
$myvar=1995;
echo "The variable is an ".gettype($myvar)."<br>";
$myvar=settype($myvar, "string");
echo "The variable is now a ".gettype($myvar);
?>

Thanks &开发者_开发技巧amp; Regads, rseni.


According to the documentation of settype it changes the variable passed by reference and returns a bool.

Thus $myvar=settype($myvar, "string"); first changes $myvar to a string and then assigns the returned bool. The correct version is:

settype($myvar, "string");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜