While comparing the values in the below array
array
0 =>
array
0 => string '09:30' (length=5)
1 => string '11:00' (length=7)
1 =>
array
0 => string '11:01' (length=5)
1 => string '18:00' (length=7)
2 =>
array
0 => string '12:05' (length=5)
1 => string '14:00' (length=7)
3 =>
array
0 => string '14:00' (length=5)
1 => string '20:20' (length=7)
If I am using if($a > $b)
it is even giving true for equal values ($a = $b) // this is not comparision
, while if($a - $b > 0)
is giving accurate result.
Why so ?
EDIT: The code part where I am using cmp.
This woks fine
for($i=0; $i < $fr -1 ; $i++)
{
if( $dtime[$i][1] - $dtime[$i+1][0] > 0 )
{
echo 'It is clashing';
break;
}
}
This does not works fine
for($i=0; $i < $fr -1 ; $i++)
{
if( $dtime[$i][1] > $dtime[$i+1][0] )
{
echo 'It is clashing';
break;
}
}
Though the way you're doing comparisons seems odd, I think you have a data cleaning problem. In the top part of your question it appears you're doing a var_dump()
. Notice how'09:30' (length=5)
is correct but '11:00' (length=7)
is wrong because the length should be 5 also. There are some additional hidden characters (maybe or ) at the beginning or end of the data.
To fix, try running $value = trim($value)
on each of your array elements before comparing.