In generating a select tag for a Boolean value, I use the following code:
<select name="name" id="id">
<option value="0"<?php if(empty($value)): ?> selected="selected"<?php endif; ?>>Off</option>
<option value="1"<?php if($value): ?> selected="selected"<?php endif; ?>>Off</option>
</select>
So, the question is, will this map correctly, so that at no point, both the options will have a selected="selected" property?
The only reason I see to use
empty()here is to avoid warnings in case$valueis not set. But in this case you get the warning next line. It’s more common and prettier to use!to negate booleans otherwise.But to answer your question, yes, your assumption is safe.
Update: The documentation explicitly states that