RobertP Posted June 8, 2012 Share Posted June 8, 2012 This is quite simple, however i would like your opinions... When should i use switch instead of ifelse ? after 2 or more possibilities? 5 or more? Currently i am using this for the most simplistic design: else if($command=='content'&&count($commands)>0){ $content = 'n/a'; if($commands[0]=='dashboard'){ $content = 'Dashboard'; } elseif($commands[0]=='settings'&&isset($commands[1])){ if($commands[1]=='general'){ $content = 'Configuration Settings = General Settings'; } elseif($commands[1]=='server'){ $content = 'Configuration Settings = Server Settings'; } elseif($commands[1]=='member'){ $content = 'Configuration Settings = Member Settings'; } elseif($commands[1]=='page'){ $content = 'Configuration Settings = Page Settings'; } elseif($commands[1]=='plugin'){ $content = 'Configuration Settings = Plugin Settings'; } elseif($commands[1]=='file'){ $content = 'Configuration Settings = File Settings'; } } styler::validExit($content); } now i think i should switch to 'switch' statements; but this is just the beginning. ps: this is the core of my administration panel for my cms. Link to comment https://forums.phpfreaks.com/topic/263841-design-pattern/ Share on other sites More sharing options...
scootstah Posted June 8, 2012 Share Posted June 8, 2012 I usually use switch when I have more than 2 cases. I think it is more of a preference thing and what you think is easier to read. I've seen some benchmarks where switch is faster and I've seen some where if/else is faster. This tells me there isn't a huge performance difference, so use whatever you like more. Link to comment https://forums.phpfreaks.com/topic/263841-design-pattern/#findComment-1352061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.