phpstuff Posted April 22, 2014 Share Posted April 22, 2014 What percentage of the time on average would you use the Switch conditional vs. the else conditional? Link to comment Share on other sites More sharing options...
HartleySan Posted April 22, 2014 Share Posted April 22, 2014 I don't think it's a percentage thing so much as a what-does-the-scenario-call-for thing. Switch statements are generally preferable when you have a bunch of string or number values that a variable can be, and you want to switch up the behavior based on what the current value is. If statements are generally more for making complex comparisons that aren't simply, "Is this variable equal to this value?" As a side note, an array or object (i.e., hash table) can often be used as a more efficient replacement of a switch statement. Please Google it for more details. Link to comment Share on other sites More sharing options...
phpstuff Posted April 22, 2014 Author Share Posted April 22, 2014 Thanks for the fast reply... I appreciate the help here.. Link to comment Share on other sites More sharing options...
Recommended Posts