I am trying to create a 2D array where $multiples[$i] = array(multiples of $i), $i = 1,2,3..
.
function getMultiples($factor, $start = 0, 10)
{
$multiples = array();
for($i = $factor + $start; $i < 10; $i+=$factor)
$multiples[] = $i;
return $multiples;
}
for($i = 2; $i < 10; $i++)
{
$start = 0 ;
$multiples[$i] = getMultiples($i, $start, 10);
}
However, when I var_dump
$multiples[2] = array(0 => 2)
$multiples[3] = array(0 => 3)
$multiples[4] = array(0 => 4)
...
Each element of $values
has been intialized with only the first multiple in each array.
I've tested this with non-numerical key values and it works fine. Static key values also work. The dynamic key value $i
seems to the problem, what is going on here?