<?php
function custombuttons_generate_children(&$options, $a, $m, $k) {
  $mcount = count($m);
  if (empty($options[$a[$k]])) {
    foreach ($m as $key => $label) {
      $new_key = implode('_', array($k, $key));
      $new_label = implode('+', array($label, $a[$k]));
      $options[$a[$k]][$new_key] = $new_label;
    }
  }
  else {
    foreach ($options[$a[$k]] as $key => $label) {
      foreach ($m as $mkey => $mlabel) {
        if (!strpos($key, '_' . $mkey)) {
          $new_key = implode('_', array($key, $mkey));
          $new_label = implode('+', array($mlabel, $label));
          $options[$a[$k]][$new_key] = $new_label;
        }
      }
    }
  }
  $last = end(array_keys($options[$a[$k]]));
  if (count(explode('_', $last)) !== $mcount) {
    custombuttons_generate_children($options, $a, $m, $k);
  }
}

function custombuttons_action_options_list() {
  $a = array(
    'left' => 'LEFT',
    'middle' => 'MIDDLE',
    'right' => 'RIGHT',
  );
  $m = array( // modifiers
    'ctrl' => 'CTRL',
    'alt' => 'ALT',
    'shift' => 'SHIFT',
    'double' => 'DOUBLE',
  );
  foreach ($a as $key => $label) {
    $options[$key] = $label;
    $options[$label] = array();
    custombuttons_generate_children($options, $a, $m, $key);
  }
print_r($options);
}
custombuttons_action_options_list();
?>