Arrays and assigning variables

This is a discussion on Arrays and assigning variables within the PHP Language forums, part of the PHP Programming Forums category; I need some help with trying to assign a string to a variable name, whilst the variable name itself is ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-22-2004
Dariusz
 
Posts: n/a
Default 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<=$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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0