How does php record physical information with SESSION?

I want to add the goods to the merchandise
I want to go to SESSION to record
but I just don"t know what the principle is?
is there a great god who can interpret it for me?
there will be a product name, slice, number of statistics
can even remove the item
to SESSION to record how to achieve?
in the past, my SESSION is always a single value
for example, $_ SESSION ["abc"] =" abc";
can save multiple values? And each has a key, value

I was going to say database records
, but is this the right method?

Mar.21,2021

$_SESSION
session_start();

$_SESSION['goods'] = [
    'name' => 'goodsname',
    'pic' => 'url',
    'price' => 10.10,
    'num' => 100,
    'summary' => 999.50
];
print_r($_SESSION['goods']);

,,

your approach and ideas are correct, but the implementation depends on the business scenario. Under normal circumstances

adding a shopping cart when a user is logged in should record the other end of Synchronize (stored in the database)
if the user is not logged in, it exists in session
if the shopping cart added by the user is not logged in, it is automatically recorded in the database after the user logs in

about the design of e-commerce, you can take a look at my article
https://codeshelper.com/a/11.

.

to put it simply, the operation SESSION can be treated as an operation array.
the landlord says how session stores shopping cart information. The demo is as follows:

// SESSION
$_SESSION['cart']['goods'] = [
    'goods_id' => [
        'goods_name' => 'goods_name',
        'price'      => 'price',
        'spec'       => 'spec',
        'num'        => 'num'
    ],
    '1' => [
        'goods_name' => '',
        'price'      => '15.00',
        'spec'       => ';',
        'num'        => '10'
    ],
    '2' => [
        'goods_name' => '',
        'price'      => '10.00',
        'spec'       => ';',
        'num'        => '5'
    ]
];

/**
 * 
 * 1SESSION
 * 2
 * 3SESSION
 */
$session_goods = $_SESSION['cart']['goods'];

$session_goods[11] = [
    'goods_name' => 'T',
    'price'      => '69.00',
    'spec'       => ':;:;',
    'num'        => '1'
];

$_SESSION['cart']['goods'] = $session_goods;


/**
 * ID1
 * SESSION
 */
unset($goods['1']);
$_SESSION['cart']['goods'] = $goods;

Shopping cart is generally stored in cache


session can be stored in an array. If you don't log in, you throw him into the session first, and then disappear when you leave the page; if you log in, you put his Synchronize into the information of the person you logged in

.
Menu