[Solved] Are this if statements equal? [closed]


Let us break it down.

isset($_SESSION['id']) == 1

The first part, the isset() call, will return a boolean value (true or false), depending on if the session id is set or not.

When you compare an integer value with a boolean value, using the == operator, the integer will be coerced (or cast/type-juggled) into a boolean value. So, if the integer is a “truthy” value, i.e. greater than or equal to 1, then it will be turned into true. If it is lower than or equal to 0 then it will be turned into false.

In other words, if the session is set then the expression will be turned into true === true (which evaluates to true). If it is not set then it will be turned into false === true (which evaluates to false).

So, in conclusion, it probably does not do what you thought it did. Use the latter if statement.

2

solved Are this if statements equal? [closed]