Variable always resetting

前端 未结 2 1407
小鲜肉
小鲜肉 2021-01-26 06:00

I\'m creating a game like mastermind using forms. My problem is that I have a variable $attempts, and I want it to increase every time the user guesses a number, but it seems to

2条回答
  •  温柔的废话
    2021-01-26 06:30

    $attempts is always equal to one because it is not inside a loop, it is declared at the end and you are just adding one to its existing value (0). You need to put it in the appropriate place (just above the last { I think) and it should work.

    Also, you seem to use different methods for adding one, such as $black + 1 and $attempts += 1;. Use $variable++, it is much easier to understand and stops any errors arising of that.

提交回复
热议问题