jHromika
02-08-2004, 10:05 PM
In order to clean up a bit of code I'm working on, I'd like to store a couple string arrays in one sort of master array so I could just loop the whole process.
Here's some sample code because I think it might be easier to read out of context (not to mention, you could actually run it)
And my apologies for reading it without tabs, doesn't seem to like that or spaces from the preview window.
// It doesn't like me defining arrays without scaler values within the masterArray, hence using $j. I'm assuming that's why I'm getting only the first seeds from each array, but this was the only way I could run the script so far...
int $j = 0;
string $array1[] = {"This ", "should ", "work."};
string $array2[] = {"I ", "think."};
string $array3[] = {"Why ", "won't ", "it?"};
string $masterArray[] = {$array1[$j], $array2[$j], $array3[$j]};
string $currentWord;
string $currentArray[];
for ($i = 0; $i <= 2; $i++)
{
$currentArray = {$masterArray[$i]};
for ($currentWord in $currentArray)
{
print $currentWord;
$j += 1;
}
print "\n";
}
So basically, what I want from that, is to cycle the whole thing 3 times. Retrive array[$i] from the masterArray, and then for each slot in array[$i] I want it to be printed out.
What I'm getting instead is slot 0 of each array.
So instead of...
This should work.
I think.
Why doesn't it?
I get...
This
I
Why
So far I haven't see any documentation on this and my guess and check methods aren't coming up with much.
Anyone have any thoughts?
Here's some sample code because I think it might be easier to read out of context (not to mention, you could actually run it)
And my apologies for reading it without tabs, doesn't seem to like that or spaces from the preview window.
// It doesn't like me defining arrays without scaler values within the masterArray, hence using $j. I'm assuming that's why I'm getting only the first seeds from each array, but this was the only way I could run the script so far...
int $j = 0;
string $array1[] = {"This ", "should ", "work."};
string $array2[] = {"I ", "think."};
string $array3[] = {"Why ", "won't ", "it?"};
string $masterArray[] = {$array1[$j], $array2[$j], $array3[$j]};
string $currentWord;
string $currentArray[];
for ($i = 0; $i <= 2; $i++)
{
$currentArray = {$masterArray[$i]};
for ($currentWord in $currentArray)
{
print $currentWord;
$j += 1;
}
print "\n";
}
So basically, what I want from that, is to cycle the whole thing 3 times. Retrive array[$i] from the masterArray, and then for each slot in array[$i] I want it to be printed out.
What I'm getting instead is slot 0 of each array.
So instead of...
This should work.
I think.
Why doesn't it?
I get...
This
I
Why
So far I haven't see any documentation on this and my guess and check methods aren't coming up with much.
Anyone have any thoughts?
