我目前在使用包含其他数组的数组时遇到问题。下面是我当前的代码。但是问题是我执行了100次相同的代码,唯一的区别是当我遍历要循环的Array内的数组时需要的$ anotherOtherIndex。
如果有人可以通过消除重复的代码来减少所需的代码量,这将对我有很大帮助。
for( $index = 0; $index < $endOfLoop; $index++ ) {
if(true) {
$myVariable = arrayWithArrays[$index][$anotherIndex]
x100...
}else{
$myVariable = arrayWithArrays[$index][$anotherIndex][$anotherOtherIndex]
x100...
}
伪代码解决方案(那是完美的,现在我们都不完美了;)):
for( $index = 0; $index < $endOfLoop; $index++ ) {
$myVariable = arrayWithArrays[$index][$anotherIndex][?????]
}