Reputation: 11
I have the value fields--mostly having leading zero values (eg. 00566478990), retrieved from .csv file. I use those fields in conditional IF. Unfortunately, the use of leading-zero values behave as same as non leading-zero values in both meet-condition and don't meet condition.
How to solve that problem, I am not sure whether the problem is with my csv file or my code?
Here is part of conditional 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?
}
I expect:
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
}
It seems that, any value leading with zero (eg. 0012345 || 012345 || 0000000...12345) is interpreted as 12345 in my case.
Upvotes: 0
Views: 34
Reputation: 11
Thanks a ton @Honk Der hase. I use strcmp(). It basically compares two given values. It returns 0 when the values are equal. So, I implemented it on my code:
$check_val=strcmp($val[1], $param1);
if($check_val == '0'){
//some logic go here;
echo $val[1];
}
Upvotes: 0