I have an idiot question but I’m stuck.
here is my simply code
$my_string = '00';
switch ((string)$my_string)
{
case '-1': $return_string = 'bla bla..'; break;
case '0': $return_string = 'One zero'; break;
case '00': $return_string = 'Double zero'; break;
default: $return_string = 'default'; break;
}
echo $return_string;
The result of the code before returns
One Zero
any suggestions ?
Well,
this is basically because php is not a strongly type language.
so “00” == “0” gives true (and as said switch uses the equality operator)
you might change this to if else statements with triple equals and that would do it.
“00” === “0” gives false. check this thread for more details. How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?