title: Use a switch statement to assign months to an array key value PHP
body: <p>I need to print the month name followed by the monthly expense for the corresponding array value (1=jan, 2=feb...ect). I have gotten pretty far and can print "Month [1] $2997.10" for example, but can't figure out how to print it in the format "Jan $2997.10". I know it's something simple I'm missing, but I've tried everything I can think of and only get error messages. Thanks in advance for your help.</p>
  
  <pre><code>     $monthly_expense = array(    '1' =&gt; 2997.10,
                                '2' =&gt; 921.00,
                                '3' =&gt; 371.99,
                                '4' =&gt; 1928.00,
                                '5' =&gt; 1206.00,
                                '6' =&gt; 10190.33,
                                '7' =&gt; 8390.35,
                                '8' =&gt; 3009.93,
                                '9' =&gt; 4803.30,
                                '10'=&gt; 1212.30,
                                '11'=&gt; 225.90,
                                '12'=&gt; 594.65
                                );
  
   //Your program starts here!
  switch ($monthly_expense) {
  case 1:
      $month = 'Jan';
      break;
  case 2:
      $month = 'Feb';
      break;
  
  case 3:
      $month = 'Mar';
      break;
  case 4:
      $month = 'Apr';
      break;
  case 5:
      $month = 'May';
      break;
  case 6:
      $month = 'Jun';
      break;
  case 7:
      $month = 'Jul';
      break;
  case 8:
      $month = 'Aug';
      break;
  case 9:
      $month = 'Sep';
      break;
  case 10:
      $month = 'Oct';
      break;
  case 11:
      $month = 'Nov';
      break;
  case 12:
      $month = 'Dec';
      break;
  default:
      $month = 'Not a valid month!';
  
      break;
  }
  
  for ($count = 1; $count &lt; sizeof($monthly_expense)+1; $count++)
       printf ("Month [%d]: $%.2f\n", $monthly_expense[$count]);
  
  
   //Compute the total of all salaries
   $totalExpense = 0.0;
  
   foreach ($monthly_expense as $value)
       $totalExpense += $value;
  
   printf ("The total company expenses for the year is $%.2f.\n", $totalExpense);
  </code></pre>