我有以下两个数组:
<?php
$a = array( // actions
'left' => 'LEFT',
'middle' => 'MIDDLE',
'right' => 'RIGHT',
);
$m = array( // modifiers
'ctrl' => 'CTRL',
'alt' => 'ALT',
'shift' => 'SHIFT',
'double' => 'DOUBLE',
);
?>
我需要得到笛卡尔积,但需要注意的是也需要组合的每种组合。当然,如果我向数组添加更多选项,它需要扩展。所以生成的列表应该输出如下:
<?php
$options['left'] = 'LEFT';
$options['LEFT'] = array(
'ctrl_left' => 'CTRL+LEFT',
'alt_left' => 'ALT+LEFT',
'shift_left' => 'SHIFT+LEFT',
'double_left' => 'DOUBLE+LEFT',
'ctrl_alt_left' => 'CTRL+ALT+LEFT',
'ctrl_shift_left' => 'CTRL+SHIFT+LEFT',
'ctrl_double_left' => 'CTRL+DOUBLE+LEFT',
'alt_shift_left' => 'ALT+SHIFT+LEFT',
'alt_double_left' => 'ALT+DOUBLE+LEFT',
'ctrl_alt_shift_left' => 'CTRL+ALT+SHIFT+LEFT',
'ctrl_alt_double_left' => 'CTRL+ALT+DOUBLE+LEFT',
'ctrl_alt_shift_double_left' => 'CTRL+ALT+SHIFT+DOUBLE+LEFT',
);
$options['middle'] = 'MIDDLE';
$options['MIDDLE'] = array(
'ctrl_middle' => 'CTRL+MIDDLE',
'alt_middle' => 'ALT+MIDDLE',
'shift_middle' => 'SHIFT+MIDDLE',
'double_middle' => 'DOUBLE+MIDDLE',
'ctrl_alt_middle' => 'CTRL+ALT+MIDDLE',
'ctrl_shift_middle' => 'CTRL+SHIFT+MIDDLE',
'ctrl_double_middle' => 'CTRL+DOUBLE+MIDDLE',
'alt_shift_middle' => 'ALT+SHIFT+MIDDLE',
'alt_double_middle' => 'ALT+DOUBLE+MIDDLE',
'ctrl_alt_shift_middle' => 'CTRL+ALT+SHIFT+MIDDLE',
'ctrl_alt_double_middle' => 'CTRL+ALT+DOUBLE+MIDDLE',
'ctrl_alt_shift_double_middle' => 'CTRL+ALT+SHIFT+DOUBLE+MIDDLE',
);
$options['right'] = 'RIGHT';
$options['RIGHT'] = array(
'ctrl_right' => 'CTRL+RIGHT',
'alt_right' => 'ALT+RIGHT',
'shift_right' => 'SHIFT+RIGHT',
'double_right' => 'DOUBLE+RIGHT',
'ctrl_alt_right' => 'CTRL+ALT+RIGHT',
'ctrl_shift_right' => 'CTRL+SHIFT+RIGHT',
'ctrl_double_right' => 'CTRL+DOUBLE+RIGHT',
'alt_shift_right' => 'ALT+SHIFT+RIGHT',
'alt_double_right' => 'ALT+DOUBLE+RIGHT',
'ctrl_alt_shift_right' => 'CTRL+ALT+SHIFT+RIGHT',
'ctrl_alt_double_right' => 'CTRL+ALT+DOUBLE+RIGHT',
'ctrl_alt_shift_double_right' => 'CTRL+ALT+SHIFT+DOUBLE+RIGHT',
);
?>