Php Programming Code Examples
Php > Arrays Code Examples
Simple script to passing persistent and growing array between recalls
Simple script to passing persistent and growing array between recalls
of one page (manipulate little stack).
<html>
<body>
<form method=post >
<select name=choices[] multiple>
<option>uno
<option>due
<option>tre
<option>quattro
<option>cinque
</select>
<input type=submit value=Ok>
<hr>
<?php
$lastInsert=$HTTP_POST_VARS[choices];
if ($lastInsert) {
$n0=count($stack);
for ($i=0;$i<$n0;$i++) {
echo "<input type=hidden name=\"stack[]\" value=\"$stack
[$i]\" >";
}
$n1=count($lastInsert);
for ($i=0;$i<$n1;$i++) {
echo "<input type=hidden name=\"stack[]\" value=
\"$lastInsert[$i]\" >";
}
/*Uncomment this to see temporary values: only for debugging purpouses.
for($i=0;$i<$n0;$i++) {
echo "<h2>STACK:</h2> $stack[$i]<br>";
}
for($i=0;$i<$n1;$i++) {
$value=$lastInsert[$i];
echo "<h2>lastInsert:</h2> $value<br>";
}
*/
}
?>
<?php
$stack=$HTTP_POST_VARS[stack];
$n=count($stack);
for($i=0;$i<$n;$i++) {
echo "$i) ".$stack[$i]."<br>";
}
$ultimi=$HTTP_POST_VARS[choices];
$n=count($ultimi);
for($i=0;$i<$n;$i++) {
echo "-> ".$ultimi[$i]."<br>";
}
?>
</form>
</body>
</html>