【问题标题】:Not able to get True result for same Values in Codeigniter (PHP)无法在 Codeigniter (PHP) 中获得相同值的 True 结果
【发布时间】:2017-07-29 10:06:24
【问题描述】:

我正在尝试比较 Codeigniter 中的两个值,但即使值和类型相同,结果也总是错误的。 我在 CodeIgniter 中使用了这段代码。 下面的代码。

$return_name = $this->db->get('feegroup');
$data = $return_name->result();
foreach($data as $d)
{
    $name = $d->name;
    if(($name) === ($this->input->post("name")))
    {
        $this->session->set_flashdata('error_message',"Sorry cannot create $name fee group, you cannot have two similar fee groups. Either edit or delete $name fee group or change name to create a new fee group.");
        redirect(base_url("feegroup/add"));
    }#EOF IF
}#EOF foreach

我使用 trim()、strlen()、is_string() 来查看结果,每次都显示为 true,但在比较相同数据时返回 false。

如果来自 DB 的值来​​自 Sample 并且如果用户输入 sample 它返回 false 但如果来自 DB 的值来​​自 Sample 并且如果用户输入 样本它返回True 它不是在检查案例。

例如:

1 父 === 父 = 真

2 父 === 父 = 假

3 父 === Sam = False

4 山姆 === 山姆 = 假

5 heLLO === hello = False

【问题讨论】:

  • 你想让`Parent === parent`返回true吗?
  • @HamzaAbdaoui:是的,亲爱的。

标签: php codeigniter


【解决方案1】:

您使用strtolower 函数将文本转换为小写并进行正确比较

if(strtolower($name) === strtolower($this->input->post("name")))

【讨论】:

    【解决方案2】:

    试试这个

    if(strcasecmp($name,$this->input->post("name")) === 0)
    

    【讨论】:

    • 它确实有效,但为什么它不像我那样工作。
    • === 检查两者是否相同,您不能使用 == 它区分大小写
    猜你喜欢
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    • 2012-08-10
    相关资源
    最近更新 更多