Arrays and assigning variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dariusz

    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
    link).

    Code:

    $AccT = array(1 => "$AccountType1" , "$AccountType2" , "$AccountType3" ,
    "$AccountType4" );
    $NumElements = count($AccT);

    if (in_array("Yes" , $row))
    {
    for($i=1; $i<=$NumElement s; $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
Working...