字符串值等于true [英] String value equals true

查看:61
本文介绍了字符串值等于true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回 TRUE FALSE "Test_operation" 的函数,并且正在循环执行某些操作.如您所见, $ comment_reply 的值为 Test_operation .

I have a function that returns TRUE or FALSE or "Test_operation", and I am looping it to do some things. As you can see the value of $comment_reply is Test_operation.

$comment_reply = $this->Profunction->insert_comments();
echo $comment_reply; // returns Test_operation
if ($comment_reply==TRUE)
{
    echo json_encode('Success');
}
elseif($comment_reply==FALSE)
{
    echo json_encode('Failed');
}
elseif($comment_reply =="test_operation")
{
    echo json_encode('This Action Cannot be done!');
}

但仍然

if ($comment_reply==TRUE)
{
    echo json_encode('Success');
}

这部分正在执行.为什么会发生?

This portion getting executed. Why does it happen?

在该函数中,我将这样返回:

In that function I am returning like this:

return TRUE;     // if all success
return FALSE;      // if there is some problems
return "Test_operation";     //No insertion need to be done,may be for preview purpose.

已解决:我将 bool 的值更改为字符串.它将是

SOLVED : I changed bool values to string. So it will be

return 'TRUE';     // if all success
    return 'FALSE';      // if there is some problems
    return "Test_operation";     //No insertion need to be done,may be for preview purpose.

推荐答案

不确定是您的问题,但是如果您想通过键入 值来强制执行相等性,请使用 === 运算符.

Not sure it's your issue, but if you want to enforce equality by type and value, use the === operator.

您可以在比较操作员页面上进行详细检查,.

快乐编码

这篇关于字符串值等于true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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