Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : Web Architecture : Education - Tutorials
Writing efficient PHP
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
2. Writing efficient code
  


Reordering switch...case statements page 10 of 15


When using a switch...case statement, try to place the most frequently-occurring cases at the top of the list. This improves speed and efficiency for the most common cases. For example:


switch ( $user->writingHand )
   {
   case 'right-handed':
      print 'User is right handed'
      break;
   case 'left-handed':      
      print 'User is left handed'
      break;
   default:
      print 'Not sure whether the user is left or right handed!'
   }

Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact