Get the array id inside the session

0

I have the session $_SESSION['linha_pedagio'][] like this:

Array
(
    [0] => Array
        (
            [0] => 2
            [1] => CGO - RJA (via Magé)
            [2] => 96.30
            [3] => 2
            [4] => 9681
        )

    [2] => Array
        (
            [0] => 4
            [1] => RJA - CPQ
            [2] => 224.70
            [3] => 2
            [4] => 493
        )

    [3] => Array
        (
            [0] => 9
            [1] => RJA - BMA
            [2] => 72.00
            [3] => 1
            [4] => 5270
        )

    [4] => Array
        (
            [0] => 
            [1] => BMA X B. PIRAI
            [2] => 20.00
            [3] => 1
            [4] => 5027
        )

    [5] => Array
        (
            [0] => 2
            [1] => CGO - RJA (via Magé)
            [2] => 96.30
            [3] => 2
            [4] => 4493
        )

)

However, I need to exclude one of the $ _SESSION arrays, which are 0, 2 or 5.

I've used unset($_SESSION['linha_pedagio'][$id]); but I've written the wrong value for the variable $id ,

Is there a way to get this parent id?

Values: 0, 2, 3, 4 and 5.

    
asked by anonymous 29.01.2018 / 14:50

1 answer

2

You can "catch" this id as follows:

foreach($_SESSION['linha_pedagio'] as $id => $objeto){
    if($id == 0 || $id == 2 || $id == 5){
        unset($_SESSION['linha_pedagio'][$id]);
    }
}
    
29.01.2018 / 15:05