I have a problem that baffles me. I have noticed this before, but still have not paid attention to it. I tried to write my own check for whole lines. I know is_numeric(), but this is not enough, because he considers it to be floatnumerical, and not just integersthat is_int(), which does not work with string numbers.
I did something like this
$var1 = 'string';
$var2 = '123';
var_dump( (int)$var1 == $var1);// boolean true
var_dump((int)$var2 == $var2);// boolean true
var_dump((int)$var1);//int 0
var_dump($var1);//string 'string' (length=6)
As expected, the second dump of var outputs true, since I expect that when comparing php with an equal value, the strings and integer versions will be equal.
However, the first time I do not understand why this is so. I tried casting on booland it still gives me the same result.
I tried to assign cast var to a new variable and compare two, all the same result
- php?
***
. , int 0 string 'string'.
-, .
***
, , 0 == 'string' . ?
*** 2
. , .