Hello,
There is a array $array = array("9","10","14","17");
I’m using foreach in two places on the page
foreach 1:
But this loop reads the array from the end, i.e. it starts at input value 17
Searches for entry 14 if there is no entry 17
Why does this foreach read the array in reverse?
What did I do wrong here?
Note: there is another database query code between two foreach loops but not using any loops
foreach($array AS $input){
// Tap off
// Here is the database query code
$tap_off->execute([$input]);
$result = $tap_off->rowCount();
// Stop loop if product
if (isset($result) && $result == 1) {break;}
// Search for next input value if product does not exist
if (isset($result) && $result == 0) {continue 1;}
}
foreach 2:
This loop searches the array from the left i.e. 9 input options
This loop is working correctly
foreach($array AS $input){
// Splitter
// Here is the database query code
$splitter->execute([$input]);
$result = $splitter->rowCount();
// Stop loop if product
if (isset($result) && $result == 1) {break;}
// Search for next input value if product does not exist
if (isset($result) && $result == 0) {continue 1;}
}
at the bottom of the page there are while() loop codes to list the products
Apart from these, do not have any other cycle