By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,712 Members | 1,498 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,712 IT Pros & Developers. It's quick & easy.

Arrays and assigning variables

P: n/a
I need some help with trying to assign a string to a variable name, whilst
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
link).

Code:

$AccT = array(1 => "$AccountType1", "$AccountType2", "$AccountType3",
"$AccountType4");
$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?

Thanks.

Dariusz
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.