Reputation: 655
<?php session_start(); ?>
$_SESSION['catRandNum'] = rand(0,2);
That is one of my variables randomly selecting a category for my hangman mini-game I am making.
Is there any way I could make the variable stay constant so the category will stay the same? Thank you for your help.
Upvotes: 0
Views: 1013
Reputation: 781370
maybe this is what you want:
if (!isset($_SESSION['catRandNum'])) {
$_SESSION['catRandNum'] = rand(0,2);
}
If this is a new session, the variable is set randomly. Otherwise it keeps its value.
Upvotes: 4