alexswear
alexswear

Reputation: 655

PHP Variables not staying constant

I am making a little Hangman game, and I have some code:

 $_SESSION['b1'] = $_SESSION['word'][0];

The word is peach at the moment, so when I guess P, I get this:

p _ _ _ _

But, say I guess e afterwards, I get this.

_ e _ _ _

Is there a way I could make p stay there after it is guessed?

Upvotes: 0

Views: 52

Answers (1)

Lajos Veres
Lajos Veres

Reputation: 13725

When you would like to change the $n. character to $something:

$_SESSION['b1'][$n] = $something;

In your case:

$_SESSION['b1'][1] = $_SESSION['word'][0];

Details:

http://www.php.net/manual/en/language.types.string.php#language.types.string.substr

Upvotes: 1

Related Questions