【发布时间】:2020-03-23 13:25:52
【问题描述】:
我目前遇到的问题是我使用包含其他数组的数组。下面是我当前的代码。然而问题是我执行了 100 次相同的代码,唯一的区别是当我循环遍历我循环的数组内部的数组时我需要的 $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][?????]
}
【问题讨论】:
标签: php arrays code-duplication