sorry this seems to be a repeated question but it confused to why I can't get a drop-down box to differentiate between null and 0.
I have a drop-down box with some PHP which select a value from a database and assigns it to $user
. The default value is null, but I then want to change it to a 0 or 2 (its for number of tickets, so null is I haven't assigned any, 0 is I don't want to give them any, and 2 is they get 2). Basically the code below doesn't distinguish between null and 0 and based on other posts I read I feel it should but obviously I'm missing something.
<option value="" <?php if( is_null($user)){ echo 'selected'; }?>>Not Set</option>
<option value="0" <?php if($user === 0){ echo 'selected'; }?>>0</option>
<option value="2" <?php if($user === 2){ echo 'selected'; }?>>2</option>
I have also tried
<option value="" <?php if($user === NULL){ echo 'selected'; }?>>Not Set</option>
<option value="0" <?php if($user === 0){ echo 'selected'; }?>>0</option>
<option value="2" <?php if($user === 2){ echo 'selected'; }?>>2</option>
and
<option value="" <?php if($user === ''){ echo 'selected'; }?>>Not Set</option>
<option value="0" <?php if($user === 0){ echo 'selected'; }?>>0</option>
<option value="2" <?php if($user === 2){ echo 'selected'; }?>>2</option>
Any help appreciated.
EDIT
var_dump($user) = string(1) "0"
This is the same where $user = NULL
and $user = 0
on my local xampp var_dump($user)=int(0)
and var_dump($user)=NULL
the same code is acting different on the live version.