[Solved] Why this result in PHP?


First of all, echo is not a function, it is a language construct and it does not actually “return” anything. echo is for outputting strings. The reason it outputs (not returns) 1 instead of true is because true is not a string, it is a boolean value and therefore when it is typecast to a string, PHP converts it to "1". If you want to see the real value of something, you need to use something like var_dump().

var_dump(true);
var_dump((string) true);
var_dump(5 === 5);
var_dump(false);
var_dump((string) false);
var_dump(5 === 6);

Output:

bool(true)
string(1) "1"
bool(true)
bool(false)
string(0) ""
bool(false)

3

solved Why this result in PHP?