grep -c -m1 "^'.$user.'" "'.$myfile.'" returns a 0 or 1 of type string
with a trailing newline character "\n". eg. ( "0\n" or "\1\n" )
Knowing that, the following should make a little more sense:
Assume $stat2 = "0\n"
1. ($stat2 == "0") is false
2. ($stat2 == '0') is false
3. ($stat2 == 0) is true
They may seem like odd results, but they are kind of odd comparisons too. (comparing a string to an integer)
In 3, the string "0\n" evaluates to an integer value of 0, so you get (0 == 0), which is true.
Here is a different way to do this you might find useful:
//make sure that $stat2 is an integer
$stat2 = (int) grep -c -m1 "^$user" "$myfile";
if($stat2){
//$stat2 is 1
}
else{
//$stats2 is 0
}