I have the following foreach being performed in PHP.
What I would like to do is instead of the $invalid_ids[] = $product_id; building and then looping around that, I would instead like to remove the entry from array that is being looped around as I'm looping around it..
For example:
If the current $product_id fails any of the test, delete the item from the $current_list array and proceed to the next iteration of the foreach loop.
I tried to do an unset($product_id) while the foreach loop header looked like this: foreach ($current_list as &$product_id) {, but the item item is still in the array.
Does anyone have any ideas on how I can go about doing this?
foreach ($current_list as $product_id) {
    // Test 1 - Is the product still active?
    // How to test? - Search for a product in the (only active) products table 
    $valid = $db->Execute("SELECT * FROM " . TABLE_PRODUCTS . " WHERE products_id = " . $product_id . " AND products_status = 1");
    // Our line to check if this is okay.
    if ($valid->RecordCount <= 0) { // We didn't find an active item.
        $invalid_ids[] = $product_id;
    }
    // Test 2 - Is the product sold out? 
    if ($valid->fields['products_quantity'] <= 0 and STOCK_ALLOW_CHECKOUT == "false") { // We found a sold out item and it is not okay to checkout.
        $invalid_ids[] = $product_id; 
    }
    // Test 3 - Does the product have an image?
    if (empty($valid->fields['products_image'])) { // Self explanatory.
        $invalid_ids[] = $product_id;
    }
}
