当您需要检查/拥有数组元素的组合时,如何避免嵌套 foreach?
示例代码:
$as = array($optionA1, $optionA2)
$bs = array($optionB1, $optionB2)
$cs = array($optionC1, $optionC2)
foreach ($as as $a) {
foreach ($bs as $b) {
foreach ($cs as $c) {
$result = $this->method($a, $b, $c);
if ($result) etc
}
}
}
任何人都有可以避免嵌套的替代方法?