Hi all,
Please help me.
I'm trying to create a multidimensional array that gets incrementally added to as my program cycles through a for loop.
With a standard array I know you can write the code:
for($i=0; $i < $numunits; $i++)
{
$array[] = $numunits * $i;
}
And that incrementally adds data to the array.
However, I've tried to do this to create a multidimensional array using the following code:
for($i=0; $i < $numunits; $i++)
{
$array[] = array($var1 => array($var2, $var2));
}
When I cycle through this resultant array, none of my data is there, but I have index numbers from 0 - 26 (which is sort of right, as there are 27 things I want in there).
I tried taking off the first use of array, like:
for($i=0; $i < $numunits; $i++)
{
$array[] = ($var1 => array($var2, $var2));
}
and that gives me a syntax error.
I tried taking off the square brackets, like:
for($i=0; $i < $numunits; $i++)
{
$array = array($var1 => array($var2, $var2));
}
But that only gives me the 27th piece of data.
Is what I am doing just insane or is there a way to do it?
Cheers,
Owen