为什么不简化?
<?php
session_start();
// Page was not reloaded via a button press
if (!isset($_POST['sub']) && !isset($_POST["add"])) {
$_SESSION['num'] = 0; // Single variable to do both
}
?>
<form method='post'>
<input type="image" name='sub' src="includes/arrow-left.png" alt="Submit" value='-' width="32">
<input type="image" name='add' src="includes/arrow-right.png" alt="Submit" value='+' width="32">
<?php
if (isset($_POST["add"])) {
$_SESSION["num"] ++;
} else if (isset($_POST["sub"])) {
$_SESSION['num']-- ;
}
$var = $_SESSION['num']; ?>
</form>
<h3><em>Substract & Add number : </em></h3>
<?php
echo "var = ", $var ;
?>
编辑:我假设图像输入以某种方式触发提交