Jump to content
Killersites Forums

Looping over a multidimensional array


Recommended Posts

$_SESSION["cart_item"] = array(
'cart_item' => array(
'id' => $id,
'product_name' => $product_name
$cart_items = $_SESSION["cart_item"];

foreach ($cart_items as $cart_item) {
echo $cart_item["id"] . $cart_item["product_name"];

I have tried several variations of the foreach loop like the one above and I mostly get the error message: Notice: Array to string conversion. When I use:

I get the following output:

array(1) { ["cart_item"]=> array(2) { ["id"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "3" } ["product_name"]=> array(2) { [0]=> string(19) "Adult Female Bike" [1]=> string(18) "Kids Unisex Bike" } } }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...