Page 1 of 1

Double Variable Array

Posted: Fri Nov 22, 2002 4:27 pm
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!

Posted: Fri Nov 22, 2002 5:17 pm
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

Grr.

Posted: Fri Nov 22, 2002 9:44 pm
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.

Posted: Sat Nov 23, 2002 8:46 am
by volka
Probably you want variable variables
take a look at http://www.php.net/manual/en/language.v ... riable.php

Posted: Sat Nov 23, 2002 12:12 pm
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 ;-)