/**
  * Translate a result array into a HTML table
  *
  * @author      Aidan Lister <*****@*****.**>
  * @version     1.3.2
  * @link        http://aidanlister.com/2004/04/converting-arrays-to-human-readable-tables/
  * @param       array  $array      The result (numericaly keyed, associative inner) array.
  * @param       bool   $recursive  Recursively generate tables for multi-dimensional arrays
  * @param       string $null       String to output for blank cells
  */
 public static function array_to_table($array, $recursive = false, $null = '&nbsp;')
 {
     // Sanity check
     if (empty($array) || !is_array($array)) {
         return false;
     }
     if (!isset($array[0]) || !is_array($array[0])) {
         $array = array($array);
     }
     // Start the table
     $table = "<table>\n";
     // The header
     $table .= "\t<tr>";
     // Take the keys from the first row as the headings
     foreach (array_keys($array[0]) as $heading) {
         $table .= '<th>' . $heading . '</th>';
     }
     $table .= "</tr>\n";
     // The body
     foreach ($array as $row) {
         $table .= "\t<tr>";
         foreach ($row as $cell) {
             $table .= '<td>';
             // Cast objects
             if (is_object($cell)) {
                 $cell = (array) $cell;
             }
             if ($recursive === true && is_array($cell) && !empty($cell)) {
                 // Recursive mode
                 $table .= "\n" . rpg_website::array_to_table($cell, true, true) . "\n";
             } else {
                 $table .= strlen($cell) > 0 ? htmlspecialchars((string) $cell) : $null;
             }
             $table .= '</td>';
         }
         $table .= "</tr>\n";
     }
     $table .= '</table>';
     return $table;
 }
 function edit_robot_update_loop_one(&$mmrpg_database_robots, &$temp_battle_rewards, &$temp_battle_settings, &$temp_player_array, &$temp_total_overflow_value, $temp_player_colours, $temp_stat_tokens, $temp_player_token, $temp_player_info, $temp_robot_token, $temp_robot_info, $temp_phase_loop)
 {
     // Collect the robot index, rewards, and settings
     $temp_robot_index = !empty($mmrpg_database_robots[$temp_robot_token]) ? $mmrpg_database_robots[$temp_robot_token] : $temp_robot_info;
     $temp_robot_rewards = !empty($temp_battle_rewards[$temp_player_token]['player_robots'][$temp_robot_token]) ? $temp_battle_rewards[$temp_player_token]['player_robots'][$temp_robot_token] : array();
     $temp_robot_settings = !empty($temp_battle_settings[$temp_player_token]['player_robots'][$temp_robot_token]) ? $temp_battle_settings[$temp_player_token]['player_robots'][$temp_robot_token] : array();
     // Collect the robot's level and experience
     $temp_robot_info['robot_level'] = !empty($temp_robot_rewards['robot_level']) ? $temp_robot_rewards['robot_level'] : 1;
     $temp_robot_info['robot_experience'] = !empty($temp_robot_rewards['robot_experience']) ? $temp_robot_rewards['robot_experience'] : 0;
     // Collect the original play and prepare the transfer abilities to them
     $temp_robot_info['original_player'] = !empty($temp_battle_settings[$temp_player_token]['player_robots'][$temp_robot_token]['original_player']) ? $temp_battle_settings[$temp_player_token]['player_robots'][$temp_robot_token]['original_player'] : $temp_player_token;
     // Check the robots's stats and collect any overflow from the max
     $temp_stat_overflow = 0;
     $temp_stat_total = 0;
     $temp_stat_values = array();
     foreach ($temp_stat_tokens as $stat_token) {
         // Collect the stats for this level
         $temp_stat_values[$stat_token]['base'] = MMRPG_SETTINGS_STATS_GET_ROBOTMIN($temp_robot_index['robot_' . $stat_token], $temp_robot_info['robot_level']);
         $temp_stat_values[$stat_token]['reward'] = !empty($temp_robot_rewards['robot_' . $stat_token]) ? $temp_robot_rewards['robot_' . $stat_token] : 0;
         $temp_stat_values[$stat_token]['total'] = $temp_stat_values[$stat_token]['base'] + $temp_stat_values[$stat_token]['reward'];
         $temp_stat_values[$stat_token]['max'] = MMRPG_SETTINGS_STATS_GET_ROBOTMAX($temp_robot_index['robot_' . $stat_token], $temp_robot_info['robot_level']);
         $temp_stat_values[$stat_token]['overflow'] = $temp_stat_values[$stat_token]['total'] > $temp_stat_values[$stat_token]['max'] ? $temp_stat_values[$stat_token]['total'] - $temp_stat_values[$stat_token]['max'] : 0;
         $temp_stat_overflow += $temp_stat_values[$stat_token]['overflow'];
         $temp_stat_total += $temp_stat_values[$stat_token]['total'];
     }
     // Update the array with collected stat values
     $temp_robot_info['robot_stats'] = $temp_stat_values;
     $temp_robot_info['robot_stats_overflow'] = $temp_stat_overflow;
     $temp_robot_info['robot_stats_total'] = $temp_stat_total;
     // Print out the robot array for debug purposes
     if (EDIT_ROBOT_UPDATES_DEBUG) {
         echo '<div class="robot_block">';
         echo '<strong class="robot_title">' . $temp_robot_token . ' (phase-' . $temp_phase_loop . ') (' . $temp_player_token . ') ' . ($temp_player_token != $temp_robot_info['original_player'] ? '[via-' . $temp_robot_info['original_player'] . ']' : '') . '</strong>';
         echo rpg_website::array_to_table(array('robot_level' => $temp_robot_info['robot_level']), true);
         echo rpg_website::array_to_table(array('robot_stats' => $temp_robot_info['robot_stats']), true);
         echo rpg_website::array_to_table(array('robot_stats_total' => $temp_robot_info['robot_stats_total']), true);
         echo rpg_website::array_to_table(array('robot_stats_overflow' => $temp_robot_info['robot_stats_overflow']), true);
         echo '</div>';
     }
     // Update the parent array with these collected details
     $temp_player_array[$temp_player_token]['player_robots'][$temp_robot_token] = $temp_robot_info;
     $temp_total_overflow_value += $temp_robot_info['robot_stats_overflow'];
 }