470,862 Members | 1,838 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

Arrays and assigning variables

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


$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?


Jul 17 '05 #1
0 1205

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ched | last post: by
19 posts views Thread by Thomas Bunce | last post: by
11 posts views Thread by - Steve - | last post: by
21 posts views Thread by Matteo Settenvini | last post: by
11 posts views Thread by Olaf \El Blanco\ | last post: by
12 posts views Thread by divya | last post: by
127 posts views Thread by sanjay.vasudevan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.