javascript中的PHP5变量未取消设置

javascript中的PHP5变量未取消设置,php,unset,Php,Unset,注意:点击左边的棋子应该取消$choice并重新加载页面。但它只是重新加载页面 我想检查javascript中的变量状态集 onclick="window.location='index.php?clear=1' 和如果清除==“1”我想用以下方法重置$choice\u 1: if ($_GET['clear']=="1") {empty($_SESSION['choice_1']);} 并重建数组并生成新的图像引用 但我所拥有的却不起作用;它从不重置或清空$choice\u 1 我有一张

注意:点击左边的棋子应该取消$choice并重新加载页面。但它只是重新加载页面

我想检查javascript中的变量状态集

 onclick="window.location='index.php?clear=1'
如果清除==“1”
我想用以下方法重置
$choice\u 1

if ($_GET['clear']=="1") {empty($_SESSION['choice_1']);}
并重建数组并生成新的图像引用

但我所拥有的却不起作用;它从不重置或清空
$choice\u 1

我有一张带有主页链接的图像:

<img onclick="window.location='index.php?clear=1'; return false;" 
src="images/WL<?php echo $_SESSION['choice_1'];?>.png" alt="pieces" width=128 height=128>
.png“alt=”pieces“width=128 height=128>
在index.php的顶部有:

图像集:

<?php 

if ($_GET['clear']=="1") {empty($_SESSION['choice_1']);}

if(!isset($_SESSION['choice_1'])) {
$chessmen = array("N","Q","R","B","K","P"); 

$random_piece = array_rand($chessmen); 
$_SESSION['choice_1'] = $chessmen[$random_piece];

unset($chessmen[$random_piece]);

$random_piece = array_rand($chessmen); 
$_SESSION['choice_2'] = $chessmen[$random_piece];
} 
?>

Empty仅确定变量是否为空,请使用unset

if ($_GET['clear']=="1") {unset($_SESSION['choice_1']);}

Empty仅确定变量是否为空,请使用unset

if ($_GET['clear']=="1") {unset($_SESSION['choice_1']);}