1 回答

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊
該函數(shù)不應(yīng)使用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 關(guān)注
- 118 瀏覽
添加回答
舉報(bào)