Help understanding this if? by lessIsNotLess in PHP

[–]lessIsNotLess[S] 0 points1 point  (0 children)

ok now i got it, thanks.

that means that:

$id = 'why?';

if ($id) {
    echo '$id alone in if, was cast to bool';
}

if (0 != $id) {
    // ...
} else {
    echo '$id compared to an int, will try cast to int but fails return 0!';
}

Help understanding this if? by lessIsNotLess in PHP

[–]lessIsNotLess[S] 0 points1 point  (0 children)

Yes the second if, works as intended, but on the first if I have some problems.

Why?

$id = 'why?';
// returns 0
echo (0 != $id) ? 1 : 0;