I have a technical question which need expert advise. I have a data in the database which is a string “true”. But when I retrieve it to test the condition, which one is more advisable to use even though they both work.
if ($data == true)
or
if ($data == "true")
My gut feeling is use “true” to test if the value stored is a string and use true without the quotes when the database value is stored as a boolean. But want to confirm with you guys.
Thanks…
Confirmed, at least almost. You’re right to check the data-type as well, however in PHP you need to use the
===operator for that:It’s called the identical operator Docs and it compares the value and the type. Often helpful.