theoneweasel77
Programmer
Is it possible to store variable names in variables. I remember reading about that somewhere but I can't remember how to do it. Thanks in advance
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
e.g. The variable is $myVar = 1, and $varHolder = "$myVar"
I'm not sure if this is indicative of what you are actually doing, but on the assumption it is, you're not quite assigning the variable correctly. $varHolder = "$myVar" will not set $varHolder to "myVar", but instead it will set $varHolder to the value of $myVar, which in your example is 1. (Remember, PHP variables are evaluated/processed/whatever inside of "".) $varHolder = '$myVar' won't work either. What you need to do is simply set $varHolder to "myVar" (no $) and $$varHolder will give you the value of $myVar.
function piece_type($piece, $color)
{
if ($color == "b")
$color == "blue";
else
$color == "red";
print $color;
if ($piece == "infantry1")
return "infantry_".$color."triangle.gif";
elseif ($piece == "infantry2")
return "infantry_".$color."circle.gif";
elseif ($piece == "infantry3")
return "infantry_".$color."square.gif";
elseif ($piece == "cavalry1")
return "cavalry_".$color."triangle.gif";
elseif ($piece == "cavalry2")
return "cavalry_".$color."circle.gif";
elseif ($piece == "cavalry3")
return "cavlary_".$color."square.gif";
elseif ($piece == "general")
return "general_".$color.".gif";
elseif ($piece == "guerilla")
return "infantry_".$color."diamond.gif";
elseif ($piece == "artillary")
return "artillary_".$color.".gif";
else
return "no such piece found";
}
$terrain = field_or_forest($var.$i);
print ("<td width=71 height=71 style=\"$$terrain\" align=center background=\"/games/images/$image\" style=\"background-repeat:no-repeat; background-position: 7px 7px\;\">");
<td width=71 height=71 style="$field" align=center background="/games/images/tp.gif" style="background-repeat:no-repeat; background-position: 7px 7px\;">c4</td>
function piece_type($piece, $color)
{
if ($color == "b")
$color == "blue";
else
$color == "red";
print $color;
switch ($piece)
{
case "infantry1":
$retval = "infantry_".$color."triangle.gif";
break;
case "infantry2":
$retval = "infantry_".$color."circle.gif";
break;
case "infantry3":
$retval = "infantry_".$color."square.gif";
break;
case "cavalry1":
$retval = "cavalry_".$color."triangle.gif";
break;
case "cavalry2":
$retval = "cavalry_".$color."circle.gif";
break;
case "cavalry3":
$retval = "cavlary_".$color."square.gif";
break;
case: "general":
$retval = "general_".$color.".gif";
break;
case "guerilla":
$retval = "infantry_".$color."diamond.gif";
case "artillary":
$retval = "artillary_".$color.".gif";
break;
default:
$retval = "no such piece found";
}
return $retval;
}
if ($pos == "a1" || $pos == "a2" || $pos == "a3" || $pos == "a4" || $pos == "b1" || $pos == "b2" || $pos == "b3"
|| $pos == "b4" || $pos == "b5" || $pos == "b7" || $pos == "b10" || $pos == "c1" || $pos == "c3" || $pos == "c5"
|| $pos == "c6" || $pos == "c8" || $pos == "c9" || $pos == "c11" || $pos == "d1" || $pos == "d2" || $pos == "d4"
|| $pos == "d5" || $pos == "d6" || $pos == "d7" || $pos == "d11" || $pos == "e1" || $pos == "e2" || $pos == "e4"
|| $pos == "e5" || $pos == "e6" || $pos == "e7" || $pos == "e9" || $pos == "e10" || $pos == "e11" || $pos == "f1"
|| $pos == "f3" || $pos == "f4" || $pos == "f5" || $pos == "f6" || $pos == "f7" || $pos == "f8" || $pos == "f9"
|| $pos == "f11" || $pos == "g2" || $pos == "g3" || $pos == "g5" || $pos == "g6" || $pos == "g7" || $pos == "g8"
|| $pos == "g10" || $pos == "g11" || $pos == "h1" || $pos == "h5" || $pos == "h6" || $pos == "h7" || $pos == "h8"
|| $pos == "h10" || $pos == "h11" || $pos == "i1" || $pos == "i3" || $pos == "i4" || $pos == "i6" || $pos == "i7"
|| $pos == "i9" || $pos == "i11" || $pos == "j2" || $pos == "j5" || $pos == "j7" || $pos == "j8" || $pos == "j9"
|| $pos == "j10" || $pos == "j11" || $pos == "k8" || $pos == "k9" || $pos == "k10" || $pos == "k11")
return "forest";
else
return "field";
function field_or_forest($pos)
{
$retval = 'field';
switch ($pos[0])
{
case 'a':
$possible_values = array (1, 2, 3, 4);
break;
case 'b':
$possible_values = array (1, 2, 3, 4, 5, 7, 10);
break;
case 'c':
$possible_values = array (1, 3, 5, 6, 8, 9, 11);
break;
case 'd':
$possible_values = array (1, 2, 4, 5, 6, 7, 11);
break;
case 'e':
$possible_values = array (5, 6, 7, 9, 10, 11);
break;
case 'f':
$possible_values = array (1, 3, 4, 5, 6, 7, 8, 9, 11);
break;
case 'g':
$possible_values = array (2, 3, 5, 6, 7, 8, 10, 11);
break;
case 'h':
$possible_values = array (1, 5, 6, 7, 8, 10, 11);
break;
case 'i':
$possible_values = array (1, 3, 4, 6, 7, 9, 11);
break;
case 'j':
$possible_values = array (2, 5, 7, 8, 9, 10, 11);
break;
case 'k':
$possible_values = array (8, 9, 10, 11);
break;
default:
$possible_values = array();
}
if (in_array($pos[1], $possible_values)
{
$retval = 'forest';
}
return $retval;
}