我有值字段 - 大部分具有前导零值(例如 00566478990),从 .csv 文件检索。我在条件 IF 中使用这些字段。不幸的是,在满足条件和不满足条件下,使用前导零值的行为与非前导零值相同。
如何解决这个问题,我不确定问题是出在我的csv文件还是我的代码上?
这是条件 IF 的一部分:
//$val[1] is value with leading zero (mostly)
//$param1 is from input form (here I use CI $this->input->post('reg-num');
if($val[1] == $param1){ //
//some logic go here;
// THE PROBLEM is HERE; as for example: I input both 0012345 and 12345 into the form, then,
echo $val[1]; //the output is 0012345 from two condition. Why is that happen?
}
我期望:
if($val[1] == $param1){ //
//some logic go here;
// as for example: I input both 0012345 into the form, then,
echo $val[1]; //the output is 0012345 but if I input 12345 it outputs "False" or another logic
}
在我的例子中,任何以零开头的值(例如 0012345 || 012345 || 0000000...12345)似乎都会被解释为 12345。
非常感谢@Honk Der hase。 我使用 strcmp()。它基本上比较两个给定值。当值相等时返回 0。 所以,我在我的代码中实现了它:
$check_val=strcmp($val[1], $param1);
if($check_val == '0'){
//some logic go here;
echo $val[1];
}