返回true输出1,但返回false输出什么 [英] returning true outputs 1 but returning false outputs nothing

查看:602
本文介绍了返回true输出1,但返回false输出什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 回声ISA(A); //输出1回声ISA(B); //输出什么。为什么没有输出0?

任何人都可以在这个问题上somelight棚?它似乎把我当成一个双重标准,当你从的角度看它是真输出作为1,但假不输出0。

再次没有什么大不了的,但我认为必须有PHP的理由来设计这样。明知可能给一些更深入地了解这个美丽的语言。

一个真正的价值将自己表现为一个可见的1,但假值不会。那么,告诉我什么是这种方法的优势在哪里?

例如功能我上面提到;

 功能ISA($输入){
    如果($输入==A):
        返回true;
    其他:
        返回false;
    万一;
}


解决方案

  

一个布尔值TRUE将被转换为字符串1。布尔值FALSE为
  转换为(空字符串)。这使得转换回来,
  在布尔值和字符串之间。


<一个href=\"http://us3.php.net/manual/en/language.types.string.php#language.types.string.casting\">http://us3.php.net/manual/en/language.types.string.php#language.types.string.casting

如果您想打印一个布尔值进行调试,您可以用var_dump或print_r的。

It's not very important but I was just curious to know the difference.

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

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

Anybody can shed somelight on this matter? It does seem to me as a double standard when you look at it from the point of view that "true" outputs as "1" but "false"does not output "0".

Again, no big deal but I think there must be a reason for PHP to be designed like that. Knowing that may give some more insight into this beautiful language.

A true value will manifest itself as a visible 1, but a false value won't. So, tell me what's the advantage of this method?

example function I referred above;

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

If you want to print a boolean for debugging you can use var_dump or print_r.

这篇关于返回true输出1,但返回false输出什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆