Double Variable Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ctfagra
Forum Newbie
Posts: 2
Joined: Fri Nov 22, 2002 4:27 pm

Double Variable Array

Post by ctfagra »

Well, hello! This is my first post here, but I hope everything works ok. I really like the looks of the message board. I hope my subject was appropriate. Here is what I'm trying to do in short:

Code: Select all

$nameArray = array("title","author","subject","date");

$titleArray = array();
$authorArray = array();
$subjectArray = array();
$dateArray = array();

while (x<=5)
&#123;
      // lots of code here, don't need help on this //
 
     $currentSection = "sample"; 
     $storyArray&#1111;x]Array&#1111;x] = $currentSection;

      // more code //
&#125;
(if x was 1, and the array started at 1) could I make the value stored in titleArray[1] = "sample"; ?

Did that make much sense...I just need to know if I can use an array variable value while referring to another variable. Whoops, that sounds confusing, but maybe you get my point. Thanks!
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

add a $ sign before each instance of x (ie. $x)

not sure what this means:
$storyArray[x]Array[x] = $currentSection;
the syntax makes no sense and appears to be invalid
ctfagra
Forum Newbie
Posts: 2
Joined: Fri Nov 22, 2002 4:27 pm

Grr.

Post by ctfagra »

Whoops, I forgot a few $'s, but that wasn't the question....I'll try again:

Code: Select all

$nameArray = array("title","author","subject","date"); 

$titleArray = array(); 
$authorArray = array(); 
$subjectArray = array(); 
$dateArray = array(); 

while ($x<=5) 
&#123; 
      // lots of code here, don't need help on this // 

     $currentSection = "sample"; 
     $storyArray&#1111;$x]Array&#1111;$x] = $currentSection; 

      // more code // 
&#125;
Now, with that corrected does anyone know if I can do this? If I can use the value in one array, as part of another variable array name? So that the move would actually read:

Code: Select all

titleArray&#1111;1] = $currentSection;
Does this make sense now or can anyone offer a new solution if this won't work? Thanks I hope someone can help.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Probably you want variable variables
take a look at http://www.php.net/manual/en/language.v ... riable.php
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post by PaTTeR »

Code: Select all

$nameArray = array("title","author","subject","date"); 

$titleArray = array(); 
$authorArray = array(); 
$subjectArray = array(); 
$dateArray = array(); 

while ($x<=5) 
&#123; 
      // lots of code here, don't need help on this // 

     $currentSection = "sample";
     $x1 = $x-1; // $nameArray&#1111;0] == title
     $to_set = $nameArray&#1111;$x1].'Array'; // titleArray if x=1 
     $&#123;$to_set&#125;&#1111;$x] = $currentSection; //titleArray&#1111;1]=sample
 

      // more code // 
&#125;
May be this is that you need ;-)
Post Reply