continue 函数正在关闭我的 PHP for 循环

continue function is shutting down my PHP forloop

所以我正在为我的客户构建一个 CSV 上传器,以便使用 PHP 将订单上传到我在 Shopify 上的网站。 如果您查看我的代码,您会看到我将 $errors 设置为 TRUE 的 2 个实例。然后,在所有错误可能性之后,我检查 $errors 是否为真,如果是,则 continue 循环以便不处理订单。出于某种原因,它会像 break 那样停止整个 forloop。社区对此有何帮助?这是我的代码:

$url = 'https://xxxxxxxxxxx:xxxxxxxxxxxx@mystore.myshopify.com/admin/orders.json';
  $rows = explode(PHP_EOL, $_POST['CSV']);
  $customer = $_POST['customer'];
  $thisID = explode(',', $_POST['IDs']);
  $lines = count($rows);
  $IDs = count($thisID);
  for ($x = 0; $x < $lines; $x++) {
    $ordtot = 0;
    $cells = str_getcsv($rows[$x]);
    $line_items = array();
    $POs = array();
if ($x > 0){
    $csmpo = $cells[0];
    $orddte = $cells[1];
    $shipvia = $cells[2];
    $shipdte = $cells[3];
    $cncldte = $cells[4];
    $ohsname = $cells[5];
    $ohsaddr1 = $cells[6];
    $ohsaddr2 = $cells[7];
    $ohscity = $cells[8];
    $ohsstate = $cells[9];
    $ohszip = $cells[10];
    $ohsphone = $cells[11];
    $oddpart = $cells[12];
    $oddupc = $cells[13];
    $oddprice = $cells[14];
    $oddordqty = $cells[15];
    $ohdnote = $cells[16];
    if ($ohsphone == ""){
        $ohsphone = "1111111111";
    }
    for($a = 0; $a <= $IDs; $a++){
        if ($a == $IDs){
            $result .= "Order " . $csmpo . " NOT processed, item " . $oddpart . " not found. Please contact the webmaster.<br>";
            $error = true;
            break 1;
        }
        $myID = explode('/', $thisID[$a]);
        $mySKU = explode('_', $thisID[$a]);
        if ($mySKU[0] == $oddpart){
            $line_items[] = array('variant_id' => $myID[1], 'quantity' => $oddordqty);
            $ordtot = $ordtot + $oddordqty;
            break 1;
        }
    }
    $lines2 = $lines - $x;
    $w = $x + 1;
    for ($y = $w; $y < $lines2; $y++){
        $cells2 = str_getcsv($rows[$y]);
        if ($cells2[0] == $csmpo){
            for($b = 0; $b <= $IDs; $b++){
                if ($b == $IDs){
                    $result .= "Order " . $csmpo . " NOT processed, item " . $oddpart . " not found. Please contact the webmaster.<br>";
                    $error = true;
                    break 1;
                }
                $myID = explode('/', $thisID);
                $mySKU = explode('_', $thisID);
                if ($mySKU[0] == $cells2[12]){
                    $line_items[] = array('variant_id' => $myID[1], 'quantity' => $cells2[15]);
                    $ordtot = $ordtot + $cells2[15];
                    break 1;
                }
            }
            $x = $x + 1;
        } else {
            break 1;
        }
    }
    if ($error){continue;}
$order = array(
  "order" => array(
    "customer" => array(
      "id" => $customer
    ),
    "financial_status" => "pending",
    "shipping_address" => array(
                        "first_name" => '',
                        "address1" => $ohsaddr1,
                        "addres2" => $ohsaddr2,
                        "phone" => $ohsphone,
                        "city" => $ohscity,
                        "zip" => $ohszip,
                        "province" => $ohsstate,
                        "country" => "United States",
                        "last_name" => $ohsname,
                        "name" => $ohsname,
                        "country_code" => "US",
                        "province_code" => $ohsstate
    ),
    /*"billing_address" => array(
                        "first_name" => '',
                        "address1" => $_POST["bill_address1"],
                        "phone" => $_POST["bill_phone"],
                        "city" => $_POST["bill_city"],
                        "zip" => $_POST["bill_zip"],
                        "province" => $_POST["bill_state"],
                        "country" => "United States",
                        "last_name" => $_POST["bill_name"],
                        "name" => $_POST["bill_name"],
                        "country_code" => "US",
                        "province_code" => $_POST["bill_state"]
    ),*/
    "line_items" => $line_items,
    "note_attributes" => array(
                    array("name" => "POnumber",
                          "value" => $csmpo),
                    array("name" => "shipdate", 
                          "value" => $shipdte),
                    array("name" => "canceldate", 
                          "value" => $cncldte)
    ),
    "gateway" => "Achim Credit Terms"
)); 
$session = curl_init(); 
curl_setopt($session, CURLOPT_URL, $url);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_VERBOSE, 0);
curl_setopt($session, CURLOPT_HEADER, 1);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($session, CURLOPT_POST, 1); 
curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($order)); 
curl_setopt($session, CURLOPT_SSL_VERIFYPEER,false);
$APIresult = curl_exec($session);
curl_close($session);
usleep(500000);
$result .= "Processed Order " . $csmpo . " for a total of " . $ordtot . " items, shipping to " . $ohdcity . ", " . $ohdstate . "<br>";
}
  }
  print_r($result);

您永远不会将 $error 重置为假,因此一旦 $error 变为真,它在所有进一步的迭代中保持真。

在循环的第一行重置 $error:

for ($x = 0; $x < $lines; $x++) {
    $error = false;
    ....