note 20140 added to language.variables.external

From: Date: Sat, 23 Mar 2002 23:09:02 +0000
Subject: note 20140 added to language.variables.external
Groups: php.notes 
Request: Send a blank email to php-notes+get-28133@lists.php.net to get a copy of this message
C-STYLE STATIC VARIABLES. Sometime it its required to keep the value of a variable thru multiple loads of the same php script. As i understand php resets php session variables this kludge allows you to keep the value of a variable, ie for use in counters and incrememnting varibales. I simply add the php echo command with the name of a variable i want to keep in a HIDDEN type field of a form, Then pick it up on re-entry and modify it again. Example <table border="1" width="223" height="79"> <tr> <td width="216" align="center" height="70"> <form method="POST" action="cards.php"> <p><font face="Arial" size="2"><input type="radio" value="hit" name="option" checked>Hit me&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" value="stick" name="option">Stick</font></p> <p><font face="Arial" size="2"><input type="radio" value="5" name="bet" checked>$5&nbsp; <input type="radio" value="10" name="bet">$10&nbsp;&nbsp; <input type="radio" value="20" name="bet">$15&nbsp; <input type="radio" value="20" name="bet">$20</font></p> <input type="hidden" value="36" name="pot"> <input type="hidden" value="<? echo $cash ?>" name="cash"> <p><font face="Arial" size="2"><input type="submit" value="PLAY" name="play"></font></p> </form> </td> </tr> </table> In the example above the value of cash is incrememted by 36 every time "pot" variable. Use the following code to pick it up and increment on re-entry. hope this helps it was cunjured up druring development of a poker game in php. -- http://www.php.net/manual/en/language.variables.external.php http://master.php.net/manage/user-notes.php?action=edit+20140 http://master.php.net/manage/user-notes.php?action=delete+20140 http://master.php.net/manage/user-notes.php?action=reject+20140

« previous php.notes (#28133) next »