Suppose I have an array.
$array1 = array('John','Mike','Tim','Dan');
Using a foreach
iteration, I'm looping through $array1
, performing a db query that returns either true
or false
so I have:
foreach ($array1 as $key => $value) {
$dbQueryResult = true; // or false depending on iteration
if($dbQueryResult === true){
// HOW DO I CHECK IF IT IS THE FIRST TIME I'M GETTING HERE
}
}
How do I check if it's the first time I'm getting a desired result in an if
statement inside a foreach
iteration like in the above example?