gpt4 book ai didi

php - 返回 true 输出 1 但返回 false 什么都不输出

转载 作者:可可西里 更新时间:2023-11-01 12:45:07 25 4
gpt4 key购买 nike

这不是很重要,但我只是想知道其中的区别。

echo isA("A");  //outputs 1

echo isA("B"); //outputs nothing. why doesn't it output 0?

任何人都可以阐明这个问题吗?从“真”输出“1”而“假”不输出“0”的角度来看,这在我看来确实是双重标准。

同样,没什么大不了的,但我认为 PHP 必须是这样设计的。知道这一点可能会让您对这种美丽的语言有更多的了解。

真值将显示为可见的 1,但假值则不会。那么,告诉我这种方法的优点是什么?

我上面提到的示例函数;

function isA($input){
if ( $input == "A" ):
return true;
else:
return false;
endif;
}

最佳答案

A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values.

http://us3.php.net/manual/en/language.types.string.php#language.types.string.casting

如果你想打印一个 boolean 值用于调试,你可以使用 var_dump 或 print_r。

关于php - 返回 true 输出 1 但返回 false 什么都不输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9764231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com