اینم کدهای foreach ای که نوشتم
کد:
<?php
require '../includes/init.inc.php';
include '../template/head.tpl.php';
$book = new Book();
$cart = @$_SESSION['cart'];
echo "<table border=1>";
$s = 0;
echo "<tr>";
echo "<th>Title</th>";
echo "<th>Price</th>";
echo "<th>Count</th>";
echo "<th>Total Price</th>";
echo "</tr>";
foreach ($cart as $bid => $c) {
$b = $book->get($bid);
echo "<tr>";
echo "<td>$b[title]</td>";
echo "<td>$b[price]</td>";
echo "<td><a href='addtocart.php?bid=$bid&c=-1'>-</a> $c <a href='addtocart.php?bid=$bid'>+</a></td>";
echo "<td>" . $b['price'] * $c . "</td>";
echo "</tr>";
$s += $b['price'] * $c;
}
echo "</table>";
echo "total price: $s";
<?