用于购物车的会话数组在php中

I have array data like with multiple sessions

$_SESSION['cart'][]['id'] = $_POST['id'];
$_SESSION['cart'][]['qty'] = $_POST['qty'];
$_SESSION['cart'][]['size'] = $_POST['size'];

Now I want to get the data like Array ( [id] => 4 [qty] => 1 [size] => 1) in every time I fetch the data with any loop.

Your question is not clear. I think what you want is an array structure like this :

<?php
$_SESSION['cart'][] = array(
 'id' => $_POST['id'],
 'qty' => $_POST['qty'],
 'size' => $_POST['size']
);

foreach($_SESSION['cart'] as $cart) {
    print_r($cart);
}

Note : the [] directive is for append an element into your array

You should assign a key for each product like below:

$_SESSION['cart'][$_POST['id']]['id'] = $_POST['id'];
$_SESSION['cart'][$_POST['id']]['qty'] = $_POST['qty'];
$_SESSION['cart'][$_POST['id']]['size'] = $_POST['size'];

You can get data as below:

foreach ($_SESSION['cart'] as $product) {
    var_dump($product);
}