using variable variables and different methods of declaring them
| From: | scott | Date: | Wed, 23 Aug 2000 06:52:17 +0000 |
| Subject: | using variable variables and different methods of declaring them | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-13094@lists.php.net to get a copy of this message | ||
I am trying to state some variables.
I want to state a variable variable/ ie one part of the variable name is
constant and the other part is different.
The constant part of the variable name is $newsItem and the other part of
the variable name has to be the number of the loop ($ie)
Here is my code:
for ($i = 1; $i < $numItems; $i++) {
$iCurr = "$i.txt";
if (!$text=fopen("$iCurr", "r"))
echo ("file $iCurr does not exist".BR);
} elseif ($numItems) {
$newsItem = fread($text, 100);
echo (NL);
echo ("-- $newsItem -------- This was printed from $iCurr
(\$iCurr)".BR);
$newsItem.$i = "$newsItem"; ######### THIS IS THE PART WHERE I WANT TO
DO VAR VARS, BUT I KNOW THAT THIS SYNTAX IS WRONG ##########
} elseif ($numItems) {
// do nothing yet
}
// echo ("this is #$i var".BR); // Prints the number of $numItems
}
Whats happening here is I have loop that is controlled by $numItems this is
going to be 5. It loops until i = 5. It reads the info in from seperate text
files, '1.txt', '2.txt', '3.txt', '4.txt',
'5.txt', etc.
I then want to set the variable $newsItem4 ($newsItem-4 is then determined
by the value of $i which increments each loop) to be $newsItem.
Can anyone help.
Thanks.
Scott.