I want to add products to my array, but every time I add a product, it replaces the old one in the array.
When I add 2 things, it works fine:
Array ( [0] => 2 [1] => 8 )
But when I try to add a third item or more, it replaces the second item in the array:
Array ( [0] => 2 [1] => 10 )
Here is my code:
session_start();
if(isset($_POST['inCart']))
{
$id = $_POST['id'];
if(!empty($_SESSION['cart']))
{
$session = $_SESSION['cart'];
$session[] = $id;
print_r($session);
}
else
{
$_SESSION['cart'] = array($id);
}
}