Problem comparing PHP with '=='
Because PHP performs type conversion, it turns a string into an integer, and its methods of operation are such that they count all numbers down to a non-numeric value. In your case, a substring ('1') (because , is the first non-numeric character). If the line starts with anything but a number, you will get 0.
The == operator performs a conversion on two values ββto try to make them the same. In your example, it converts the second value from the string to an integer, which will be 1 . This is obviously equal to the value you match.
If your first value was a string, i.e. '1' in quotation marks, not an integer, then the match would fail, since both sides were strings, so he would do a string comparison and they would be different strings.
If you want an exact match operator that does not perform type conversion, PHP also offers a triple equal operator, === , which might be what you are looking for instead.
Hope this helps.
The output should be:
in From the PHP documentation:
When converting from a string to an integer, PHP parses a single character string until it finds an asymmetric character. (A number may optionally begin with a + or - sign.) The resulting number is analyzed as a decimal number (base-10). Failure to parse a valid decimal value to 0.