Switch Accepts Arrays

by Jun 22, 2011

Did you know that the Switch statement can accept arrays? Use this sample to translate numbers into words:

PS> switch ( 1,5,2,4,3,1 ) {
  1 { 'one' }
  2 { 'two' }
  3 { 'three' }
  4 { 'four' }
  5 { 'five' }
}
one
five
two
four
three
one

 

Twitter This Tip!
ReTweet this Tip!