After all this time I have been checking on a variable with both isset() && ! empty()
function as following.
if ( isset($my_arr['myh_index']) && ! empty($my_arr['myh_index']) ) { ... }
Because I though I have read somewhere that isset()
function only checks if a variable is set, it will also return true even a variable contains null or an empty string. That's why I also check with !empty()
function to make sure.
Today, I found out that the difference is that !empty()
function does not generate any warning or notice message.
Can I just only check with if ( ! empty($my_arr['my_index']) ) { ... }
to prevent
- 'Notice (8): Undefined variable'
- 'Warning (2): Illegal string offset'
- 'Notice (8): Undefined index'
?