PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
<?php
print initialize('int'); // prints 1
print initialize('blob'); // prints 1
?>
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.
The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found with a value that matches the value of the switch expression does PHP begin to execute the statements. PHP continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don't write a break statement at the end of a case's statement list, PHP will go on executing the statements of the following case.
The default is the LAST statment in the sequence. If 'int' is encountered, the break; bypasses all subsequent statements within the switch.
Thanks! I will definitely do that. I have been working with PHP only a few weeks now, but other than some small quirks, I find it an awesome language to work with