1 回答

TA贡献2039条经验 获得超7个赞
该函数不应使用for loop. 它将打印所有符合条件的条件。您需要 acondition来显示一张图像。这是代码
<?php
// Just for the sake of calling
$_SESSION['numwrong'] = 2;
$dude = [
'<img id="hung"src="images/hangman00.png"/>',
'<img id="hung"src="images/hangman01.png"/>',
'<img id="hung"src="images/hangman02.png"/>',
'<img id="hung"src="images/hangman03.png"/>',
'<img id="hung"src="images/hangman04.png"/>',
'<img id="hung"src="images/hangman05.png"/>',
];
function drawdude(){
global $dude;
if(isset($_SESSION['numwrong']) && $_SESSION['numwrong'] <= 5){
echo $dude[$_SESSION['numwrong']];
} else{
echo '</img>';
}
}
// Call the function
drawdude();
?>
- 1 回答
- 0 关注
- 87 浏览
添加回答
举报