0

I am passing arrays from a product page and using the $_GET['id'] to store product ids in 'id' then storing it in session['items'].

On the cart page, I would like to echo out only the 'id' elements of the array and not the qty. But I still want to keep the current code where $item and $value are echo.

Add-to-cart.php

**code
session_start();

$_SESSION['items'][]=array(     
                            'id'=>"'".$_GET['id']."'",
                            'qty'=> 1                           
                        );  
?>

Cart.php

**code
<?php
session_start();
foreach($_SESSION['items'] as $items=>$values)
{
foreach($values as $item=>$value)
{
//// I want to keep this, 
    echo $item;

    echo $value."<br/>";
    echo "</br>";
//// I want to keep this  
//// echo 'id' values here!
 }
}
?>

1 Answer 1

1

You'll want echo $value['id'];

<?php
session_start();
foreach($_SESSION['items'] as $items=>$values)
{
foreach($values as $item=>$value)
{
//// I want to keep this, 
    echo $item;

    echo $value."<br/>";
    echo "</br>";
    //// I want to keep this  
    echo $value['id'];
 }
}
?>
Sign up to request clarification or add additional context in comments.

3 Comments

What would echo $value echo?
@Terminus I expect it would echo Array. Not my problem though, that's what the OP says he wants.
figured that. Thought it might do something I didn't know

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.