<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $products = json_decode(file_get_contents('../js/products.json'), true);
    $products = array_filter($products, fn($p) => $p['id'] !== $_POST['id']);
    file_put_contents('../js/products.json', json_encode(array_values($products), JSON_PRETTY_PRINT));
    header('Location: main.php');
    exit;
}