Do you have a question? Post it now! No Registration Necessary. Now with pictures!
September 22, 2004, 6:57 pm
rate this thread
the variable name itself is read out of an array. The code below is part
of a routine in a database which checks if the word "Yes" is input into an
entry, then assigns a string to a variable name (the string is a HTML img
$AccT = array(1 => "$AccountType1", "$AccountType2", "$AccountType3",
$NumElements = count($AccT);
if (in_array("Yes", $row))
for($i=1; $i<=$NumElements; $i++)
$AccT[$i] = '<img src="tick.png">';
// $AccountType1 = '<img src="tick.png">';
// $AccountType2 = '<img src="tick.png">'; <-- etc...
// Commented out is cheat method,
// not using an array.
If I substitute the $AccT[$i] for the actualy string name I want, ie
$AccountType1, the in_array() code does successfully execute. So I can
only assume that I have written something wrong in the way I have wanted to
assign $AccT[$i] with a variable name and so the string I want it to have.
The "cheat" method I commented out is not preferable because as the number
of AccountTypes grows, so would the code, and I'd have to keep coming back
to amend the code.
Can anyone correct my mistake / offer a solution?