나는 단 하나의 계산서를 계산대에 게시했지만 반복되는 여러 필드를 게시하려면 양식이 필요합니다.다차원 배열 PHP 오류
내 배열은 지금
Array
(
[0] => Array
(
[id] => 65983c1c16d925e9a8cc4c4b3bdda1f5
[item] => Array
(
[1] => Brent New Product
[2] => Crazy Product
)
[unitprice] => Array
(
[1] => 100
[2] => 125
)
[quantity] => Array
(
[1] => 1
[2] => 1
)
)
)
을 보여주고있다 그러나 그것은 나의 양식은 모든 값을 수집이 PHP 스크립트로 이동이
page에서 게시하는 경우
Array
(
[0] => Array
(
[id] => 65983c1c16d925e9a8cc4c4b3bdda1f5
(
[product] => Brent New Product
[unitprice] => 100
[quantity] => 1
)
[id] => 4326526662262
(
[product] => Brent New Product2
[unitprice] => 140
[quantity] => 5
)
)
)
처럼 표시 할 필요가있다. 그것은 신갈 배열 전에 일,
session_start();
$price = $_POST['price'];
$id = $_POST['id'];
$item = $_POST['item'];
$quantity = $_POST['quantity'];
echo '<h1>Add to cart</h1>';
echo "<p>Thank you for wanting a <strong>$item</strong>!</p>";
//We define an associative array with the details of our new item
$cart_row = array(
'id' => md5(rand()),
'item' => $item,
'unitprice' => $price,
'quantity' => $quantity
);
그런 다음 카트 페이지에 나는 바구니에 항목을 표시하고자하지만 난 아무것도 채우기 상자를 얻을.
session_start();
foreach($_SESSION['cart'] as $item) { ?>
<tr>
<td><?php echo $item['item']; ?></td>
<td><?php echo $item['unitprice'];?></td>
<td><?php echo $item['quantity']; ?></td>
<td></td>
<td><form id="id" name="id" method="post" action="cart.php?remove=<?php echo $item["id"] ?>">
<input name="id" type="hidden" id="id" value="<? echo $item["id"]; ; ?>" />
<input name="Submit" type="submit" class="formbox" value="remove" />
</form></td>
</tr>
<?php } ?>
원하는 출력은 n입니다. ot 유효한 PHP 배열 ... 하위 배열에 대한 누락 된 키 –
어떻게 키를 사용하여 수정하겠습니까? – Brent