problem with 'switch' and strings
Posted: Sun Sep 07, 2003 12:34 pm
Ok, I have written an initialization function for database fields, I was trying to use a switch statement to check the field type. The basic php code is:
If I make the following calls:
I get a return value of 1 for each. However, if I use a typical if...elseif, I get the proper values returned. Does switch only work for integer values or something? The documentation does not elude to it NOT working for strings.
Code: Select all
<?php
function initialize($fldtype)
{
switch ($fldype)
{
case "string":
case "blob":
case "datetime":
$ini = "''";
break;
case "int":
$ini = 0;
break;
case "real":
$ini = 0.0;
break;
case "text":
$ini = "''";
break;
default:
$ini = 1;
}
return $ini;
}
?>Code: Select all
<?php
print initialize('int'); // prints 1
print initialize('blob'); // prints 1
?>