更新数量会话数组

I need a help

This is my session array:

Array
(
    [menu] => 
    [id] => 3
    [products] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name] => Produkt 1
                    [code] => 1
                    [varianta] => 
                    [pocet] => 1
                    [price] => 20
                    [pricepredtym] => 40
                )

            [1] => Array
                (
                    [id] => 2
                    [name] => Produkt 1
                    [code] => 1
                    [varianta] => 
                    [pocet] => 1
                    [price] => 20
                    [pricepredtym] => 40
                )

        )

)

I would need about something like, if ($_GET [id] == $ _SESSION ['products'] [id]) and only change this "[pocet]" where [id] = 2

$_GET [id] = 2; $pocet=5;

[1] => Array
                (
                    [id] => 2
                    [name] => Produkt 1
                    [code] => 1
                    [varianta] => 
                    [pocet] => 5
                    [price] => 20
                    [pricepredtym] => 40
                )

You could index your products array by product id. Then updating would be simply:

if(isset($_SESSION['products'][$prod_id])) {
    $_SESSION['products'][$prod_id]['pocet'] = $pocet;
}

Otherwise, use a foreach loop:

foreach ($_SESSION['products'] as $i => $prod) {
    if ($prod['id'] == $prod_id) {
        $_SESSION['products'][$i]['pocet'] = $pocet;
        break;
    }
}

Compare your GET value with 2 and use it as key of SESSION array.

if ($_GET['id'] == '2'){
    $_SESSION['products'][$_GET['id']]['pocet'] = '5';
}