如何使变量值在第二个嵌套的 while 循环中可用


How to make variable value available in a second nested while loop?

我目前有一个 while 循环,其中运行另一个 while 循环,我想引用一个值,每次运行第二个循环时,第一个循环都会更改该值。

$counter = 0;
$counter2 = 2;
while ($counter < 7) {
    $name = 0;
    while ($array[$counter2][2] == !false) {
        if ($array[$counter2][3] == "string") {
            if ($array[$counter2][2] == $counter) {
                $name = 1;
            }
        }
        $counter2++;
    }
    $counter++;
}

当我运行上述内容并执行第二个 IF 语句时,$counter的值为 0,即使这应该通过第一个循环的每次迭代上升。

如何在第二个 while 循环中获取 $counter 的值以匹配我在第一个 while 循环中使用的$counter?

第二个循环只运行一次,因为数组搜索总是以 false 开头,因为我没有在每次运行第一个循环时重置第二个计数器。