PHP Variables

From: Date: Wed, 23 Aug 2000 15:50:37 +0000
Subject: PHP Variables
Groups: php.general 
Request: Send a blank email to php-general+get-13168@lists.php.net to get a copy of this message
Thanks for the help earlier guys. Here is my message: I want to create a variable, consisting of a common, standard string and the value of a variable. The constant part of the variable name is $newsItem and the other part of the variable name has to be the value of $i (a number which is derived from a loop) 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. What I want to do is set a variable with $newItemX and then get X replaced by $i everytime the movie loops. Does anyone use Macromedia Flash here. If I was using flash I would go Set Variable: "$newsItem"&$i = $text For the example $i can be equal to 3, and $text can be equal to 'hello world' so $newsItem3 = 'hello world' Then when you printed this in PHP. ie/ echo ($newsItem3); // Prints Hello World Can anyone help. Thanks Scott.

« previous php.general (#13168) next »