PHP更新我的数据保持附加我的代码错误[关闭]

Can someone tell me what is wrong with my code? PHP update my Data keeps Appending

<?php

foreach($_SESSION["product"] as $index => $product)
    {
    if ($_SESSION["product"][$index]["item_id"] == $_POST["item-id"])
        {
        $found = 1;
        $target_index = $index + 1;
        }
    }

if (true)
    {
    array_push($_SESSION["product"], ["item_id" => $_POST["item-id"], "item_qty" => $_POST["item-qty"]]);
    }
  else
    {
    $qty = strval(($_SESSION["product"][$target_index]["item_qty"]) + $_POST["item-qty"]);
    $_SESSION["product"][$target_index]["item_qty"] = $qty;
    $qty = 0;
    }
}

If you are asking why it always appends to the array instead of executing the else block, it looks like you have a condition missing in the line that says:

if(true)

This will always evaluate to true no matter and as a result it will always append to your array.

You probably want to put some sort of condition there