php可以在浏览器中直接回显boolean true吗? [英] Does php can directly echo boolean true in browser?
本文介绍了php可以在浏览器中直接回显boolean true吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php
function show(){
$num=rand(0,1);
if ($num===1){
return true;
}
else
return false;
}
echo (boolean)show();
?>
即使我将它转换为布尔值,它只显示为1时为真。
但是我读了一本PHP书,告诉它有效。这让我感到困惑。
感谢您的帮助。
even though I cast it to boolean it only show 1 when true.
But I read a php book which tell it works. This let me confused.
Thank you for your help.
推荐答案
num = rand( 0 , 1 );
if (
num=rand(0,1); if (
num === 1){
返回 true;
}
else
return false;
}
echo(boolean)show();
?>
num===1){ return true; } else return false; } echo (boolean)show(); ?>
即使我将它转换为布尔值,它只显示为1时为真。
但是我读了一本PHP书,告诉它有效。这让我感到困惑。
感谢您的帮助。
even though I cast it to boolean it only show 1 when true.
But I read a php book which tell it works. This let me confused.
Thank you for your help.
如果您的目的仅仅是回应结果,为什么不简单地返回'true'和'false '作为字符串?
如果必须返回值(0或1),则将您的ECHO更改为以下内容:
ECHO((布尔)show()== 1)?'true':'false';
编程是保持简单是最好的。
If your purpose is merely to echo the result, why not simply return 'true' and 'false' as strings ?
If you must return the value (which is 0 or 1), then change your ECHO to the following:
ECHO ((boolean)show()==1)?'true':'false';
Programming is at is best when you keep it simple.
这篇关于php可以在浏览器中直接回显boolean true吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文