基本上,这是一个网页,在这里有人会按下一个按钮来递增$selection变量。全局变量和静态变量似乎不起作用。代码如下所示:
<?php
if(isset($_POST['next']))
{
displaynext();
}
else
{
global $image_folder = "/images/";
echo "global declared";
global $selection;
$selection = 1;
}
function displaynext()
{
$selection++;
if (file_exists($image_folder."/".$selection.".png")) {
echo "<img src=\"$image_folder/".$selection.".png\">";
}
else {
echo "No next image was found for $selection in ".$image_folder."/".$selection.".png";
}
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="next" value="Next">
</form>发布于 2010-07-31 02:01:57
为什么不使用$_SESSION变量而不使用全局变量呢?
https://stackoverflow.com/questions/3374162
复制相似问题