note 20140 deleted from language.variables.external by philip
| From: | philip@php.net | Date: | Mon, 01 Apr 2002 05:37:48 +0000 |
| Subject: | note 20140 deleted from language.variables.external by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-28452@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 <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
<input type="radio" value="10"
name="bet">$10 <input type="radio"
value="20" name="bet">$15
<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.