I have this piece of code:
$exists = false;
foreach ($outsiderTests as $key => $outsiderTest) {
$textExists = null;
foreach ($tests as $test) {
if ($outsiderTest->getName() == $test->getName()) {
$exists = true;
$existingTest = $test;
break;
} else
$exists = false;
}
var_dump($existingTest, $test);
}
As you can see, I want to see if there is an equivalent to an outsiderTest
in $tests
array. I thought I would have to save the existing equivalent $test
on another variable as it would be gone after the foreach
ends, but it does not.
The value of $existingTest
and $test
is the same when I dump them. This is cool, and makes me able to get rid of the mentioned $existingTest
variable, but makes me wonder if I am understanding PHP's loop functionality.
Doesn't the $test
variable only exist inside the foreach scope? Does PHP temporarily save the value of the last index the execution has run through?