I have a table of codes in a database. One of the codes has the id of 0.
I'm making a search function and I want one of the filters to be the codes, but it's optional. So, I need to differentiate between "0" and null in an if
statement.
Here is one idea that looks to me like it would work...
if ( 0 < (int)$input['code'] or false !== strpos($input['code'], "0") ){
// filter the search with the code
}
From this answer to a general question there are not that many differences between 0 and null. isset()
might be one but empty()
will not work. I'm not absolutely sure if the input is null or "" after it has been processed, I think it may be "". If this is the case, isset()
will not work either.
Is there a better way to differentiate between 0 and null/""?