次のコードがあります。選択したアイテムを追跡し、配列から下に表示しようとしています。
<?php
session_start();
//temp stores the submitted value
$temp = $_POST['field'];
if (!isset($_SESSION['itemsList'])) {
$itemsList = array();
} else {
$itemsList = $_SESSION['itemsList'];
}
//check how many elements in array
$arraySize = count($itemsList);
//set that as i and then add after that
$emptyval = "";
if (strcmp($temp,$emptyval)!=TRUE) {
array_splice($itemsList, $arraySize+1, 0, $temp);
unset($temp);
unset($_SESSION['field']);
$_SESSION['itemList'] = $itemList;
}
?>
<html>
<head>
<title>Test Page Khalid</title>
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<table height="100%" width="100%" cellspacing="10" cellpadding="10" border="1">
<tr>
<td align="center"><input name="field" value="shirt" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input name="field" value="pants" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input name="field" value="socks" style="width:200px; height:100px;" type="submit"/></td>
<tr>
<tr>
<td align="center"><input name="field" value="dress" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input name="field" value="skirt" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input name="field" value="topbody" style="width:200px; height:100px;" type="submit"/></td>
<tr>
<tr>
<td align="center"><input name="field" value="sheets" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input name="field" value="pillowcover" style="width:200px; height:100px;" type="submit"/></td>
<td align="center"><input name="field" value="blanket" style="width:200px; height:100px;" type="submit"/></td>
<tr>
</table>
</form>
<br><br><br>
<?php
$itemsReturned = $_SESSION['itemList'];
echo "The items stored are: <br>";
print_r($itemsReturned);
?>
</body>
</html>
これが何も表示されない理由は何ですか? ありがとう、