Fatal error: Uncaught Error: Undefined constant "​" and array question

Fatal error: Uncaught Error: Undefined constant "​" and array question

我正在尝试制作一个 foreach 函数,其中 phpmyadmin 中的 table 中的数字将在数组中的每个时间值与“pet_id”匹配时增加。而且这只会在按下提交按钮时执行。这是我在 php 文件中的代码:

<?php
    if (isset($_POST['Submit'])) {
        if (isset($cart)) {
            // if product appeared
            foreach ($product->getData('cart') as $item):
                $cart = $product->getProduct($item['pet_id']);
                $subTotal[] = array_map(function ($item){
                    $sql = "UPDATE pet_info SET number_sold = number_sold + 1 WHERE 
                    $item == pet_info.pet_id;";

                    $query1 = mysqli_query($con,$sql);
                    while ($pet_id = mysqli_fetch_array($query1)) {
                        execute($pet_id['pet_id']); 
                    }
                }); 
            endforeach;
        }   
    }​
?>

但我花了最后 2 个小时寻找解决方案,但我得到的仍然是错误:

Fatal error: Uncaught Error: Undefined constant "​" in C:\xampp\htdocs\testing\petsonthenet\partial\_checkout.php:121 Stack trace: #0 C:\xampp\htdocs\testing\petsonthenet\user_cart.php(7): include() #1 {main} thrown in C:\xampp\htdocs\testing\petsonthenet\partial\_checkout.php on line 121

有人可以帮帮我吗?我将不胜感激!!

这是与购物车相关的代码部分

                <?php
                foreach ($product->getData('cart') as $item) :
                    $cart = $product->getProduct($item['pet_id']);
                    echo gettype($item);
                    $subTotal[] = array_map(function ($item){
            ?>
            <!-- cart item -->
            <div class="row border-top py-3 mt-3">
                <div class="col-sm-2">
                    <img src="<?php echo $item['image'] ?? "./images/pet (1).jpg" ?>" style="height: 150px; width:120px;" alt="cart1" class="img-fluid">
                </div>
                
                <div class="col-sm-8">
                    <h5 class="font-baloo font-size-20"><?php echo $item['name'] ?? "Unknown"; ?></h5>
                    <h5 class="font-baloo font-size-20"><?php echo $item['pet_id'] ?? "Unknown"; ?></h5>
                    <small> <?php echo $item['breed'] ?? "Brand"; ?></small>
                        
                </div>

                <div class="col-sm-2 text">
                    <div class="font-size-20 text-danger font-baloo">
                        $<span class="product_price" data-id="<?php echo $item['pet_id'] ?? '0'; ?>"><?php echo $item['price'] ?? 0; ?></span>
                    </div>
                </div>
                <form method="post">
                            <input type="hidden" value="<?php echo $item['pet_id'] ?? 0; ?>" name="pet_id">
                            <button type="submit" name="delete-cart-submit" class="btn font-baloo text-danger px-3 border-right">Delete</button>
                </form>
            </div>
            <!-- !cart item -->
            <?php
                        return $item['price'];
                    }, $cart); // closing array_map function
                endforeach;
            ?>

我刚刚检查了你的错误信息,其中有一个 unicode 字符没有正确显示,在引号中。 所以我确定这是一个“打字错误”,如果我没记错的话你使用的是 mac 或 linux,然后打开越南打字机。

您可以将错误消息粘贴到浏览器的 javascript 控制台中。您将看到错误字符。

你有一个 zero width space,特别是 <0x200b>(在简单的文本编辑器中不可见),在最后一个大括号之后:

...
            endforeach;
        }   
    }​  //<-- here
?>

这似乎是一个未定义的 constant 到 PHP。

删除最后一个大括号之后的内容。