printing multi dimentional array
Posted
by Honey
on Stack Overflow
See other posts from Stack Overflow
or by Honey
Published on 2010-05-12T08:54:26Z
Indexed on
2010/05/12
9:04 UTC
Read the original article
Hit count: 440
i have this multi dimentional array that i want to print into a table having each record/item go into its own row but it goes column wise. this is the output that im getting: http://mypetshopping.com/product.php
ps: the value of $product will by dynamic based on what product is being viewed.
<?php
session_start();
?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Hash</th>
<th>Quantity</th>
<th>Size</th>
<th>Color</th>
</tr>
</thead>
<tbody>
<?php
function addCart($product, $quantity, $size,$color) {
$hash = md5($product);
$_SESSION['cart'][$product]['name'] = $product;
$_SESSION['cart'][$product]['hash'] = $hash;
$_SESSION['cart'][$product]['quantity'] = $quantity;
$_SESSION['cart'][$product]['size'] = $size;
$_SESSION['cart'][$product]['color'] = $color;
}
addCart('Red Dress',1,'XL','red');
addCart('Blue Dress',1,'XL','blue');
addCart('Slippers',1,'XL','orange');
addCart('Green Hat',1,'XXXL','green');
$cart = $_SESSION['cart'];
foreach($cart as $product => $array) {
foreach($array as $key => $value) {
?>
<tr>
<td><?=$value;?></td>
<td><?=$value;?></td>
<td><?=$value;?></td>
<td><?=$value;?></td>
<td><?=$value;?></td>
</tr>
<?php
}
}
?>
© Stack Overflow or respective owner