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!
Just a note, to avoid being unable to read your code as your projects develop try not to ever have more than one instruction on a line. Yes it makes things more compact, e.g.:
<?php
switch($var){
case "red": $thisvar="FF0000"; break;
case "green": $thisvar="00FF00"; break;
case "blue": $thisvar="0000FF"; break;
default: $thisvar="000000";
}
?>
but it will make debugging hell at some point. Especially when you are looking for parse errors on a particular line number, if you have three instructions on a line it's three times the debugging. So the following would be a better way (IMHEO) to structure the above switch statement:
I'd use this if a switch/case was very long - jumps straight to the required fn rather than checking lots of cases.
However the switch case (or if/else) is easier to read since you can see what's going at a glance. Also, you cannot set a default action with variable fns.
Last edited by McGruff on Wed Aug 10, 2005 2:53 pm, edited 1 time in total.
of course
I only wanted to point out that you have to do some extra checking before blindly relying on $var(), esp. if it somehow derives from user-input