My php variable has 3 possible values assigned, depending on a value of $_POST variable. Possible values are 'YES','NO' and 0 (zero). I'm trying to convert 0 to null value but end up converting 'YES' and 'NO' values to null as well.
echo $used;
//outputs: YES
echo gettype($used);
//outputs: string
//so far it works fine
if($used == 0)
{
$used = null;
}
echo $used;
//outputs:
echo gettype($used);
//outputs: null
//So it converted my variable to null.
//I could probably try a workaround by doing
if($used != 'YES' && $used != 'NO')
{
$used = null;
}
//or maybe even using =='0' in the conditional but I prefer to learn why this is happening before moving forward
I found Null vs. False vs. 0 in PHP and it seems that my problem might be in == 0 but I'm not sure. Thank you in advance.