title: Calculating Median of an array in PHP
body: <p>I'm trying to figure out how to calculate the median of an array of randomly generated numbers. I have the array all set up, but I'm having trouble putting together a function for the calcuation. </p>
  
  <p>This is what I have so far: </p>
  
  <pre><code>//array 
  $lessFifty = array();
  $moreFifty = array();
  
  //number generation
  for ($i = 0; $i&lt;=30; $i++) {
        $number = rand(0, 100);
  
  //Sorting &lt;50&gt;      
  if ($number &lt; 50 ) {
      $lessFifty[] = $number;
  } else {
      $moreFifty[] = $number; 
     } 
  }
   echo print_r($lessFifty); 
   echo "&lt;br&gt;" ;
   echo print_r($moreFifty);
  
     //Average
  echo "&lt;p&gt; Average of values less than fifty: &lt;/p&gt;";
      print   array_sum($lessFifty) / count($lessFifty) ;
  echo "&lt;p&gt; Average of values greater than fifty: &lt;/p&gt;" ;  
      print   array_sum($moreFifty) / count($moreFifty) ;
  
  //Median
  $func = function (median ($array, $output = $median)){ 
      if(!is_array($array)){
          return FALSE;
      }else{
          switch($output){
                  rsort($array);
                  $middle = round(count($array) 2);
      $total = $array[$middle-1];
          break; 
      return $total;
      }
  }
  
  echo $func ; 
  </code></pre>
  
  <p>I'm pretty sure that I'm doing this median section completely wrong. I'm just learning and its proving to be a challenge. </p>