evaluating the required input from a html field which holds 0 as value?
I have some of radio buttons and checkboxes elements in my HTML form which holds 0 as value. typically i would check for the required values using two functions isset()
or !empty()
while isset()
works qu开发者_高级运维ite well without hindrance but this is not the case with empty()
as logically 0 represents boolean and hence empty(0)
returns true. which is kind of bug when you evaluates integer 0 using empty()
. i would like to know the workaround so that it evaluates integer empty(0)
as false. one solution i could think of was using strlen($variable) >= 1
, is there any better way or it is fine using strlen()
?
thank you
You can check if a variable is exactly a value with three equals: ===
if( $variable === 0 ) {
will only be true if the variable is actually 0.
Use triple equal $variable===0
精彩评论