Nested switch in PHP 5.6 syntax

I had a bit of trouble with nested selects in PHP 5.6 (not sure of the differences for other versions).  I went down the wrong path of thinking my problem was with global vs. local variable scope, but that wasn't the case. The PHP documentation doesn't go enough detail for nested switches as far as having multiple default outcomes, but this works.  Example:


$color = "red";
$size = "large";

switch ($color) { 
   case "blue": $sku = "5327"; break; 
   case "white": $sku = "5328"; break; 
   case "red":   
      switch ($size) {   
         case "small": $sku = "5329-1"; break;   
         case "medium": $sku = "5329-2"; break;    
         case "large": $sku = "5329-3"; break;    
         default:    
            $sku = "5329";    
            break;  
      };                 
      break; 
   default:  
      $sku = "0";  
      break;
}

Comments

Popular posts from this blog

usoclient.exe in Windows 10 wakes up my PC with Wake Source: Unknown

How to block the Admiral anti ad-block detection message

Diskpart - "The volume you have selected may not be extended" on Windows 2003 Server when enlarging boot disk (C:) in VMware ESX 3.5