Thursday, 3 October 2024

Isset(), empty(), and checking a variable for true behave in PHP

Key Differences:

Variable Stateisset()empty()$var == true
Unset/undefinedfalse (Notice)true (No Notice)Notice/Error
nullfalsetruefalse
"" (empty string)truetruefalse
falsetruetruefalse
0truetruefalse
1truefalsetrue
"0" (string "0")truetruefalse
truetruefalsetrue
Non-empty string "abc"true            falsetrue        
[]true            truefalse

 

 Thank you

No comments:

Post a Comment

Golang Advanced Interview Q&A