<?php
$start = 1;
$times = 2;
$answer = array();
for ($start; $start < 11; $start++) {
$answer[$start] = $start * $times;
// print $answer; // will print "Array" and/or give an "Array to string conversion" error,
// because $answer is an array (which is not something you can print).
// do this instead:
print $answer[$start];
// if you expect each number to be on its own line,
// you also need to do
print "\n";
// and/or (if you're outputting HTML)
print '<br>';
}
tested.
2
4
6
8
10
12
14
16
18
20
* note, you don't get a "22" line because your loop only runs while [font=monospace]$start[/font] is less than eleven. You can do [font=monospace]$start <= 11[/font] if you want to change that.
if you really wanted to end up with 4 ... 22, don't increment in the for() construct - increment before you multiply instead.
IF that's what you want. Seems a potential source of confusion/bugs to me. But whatever. [noparse]🙂[/noparse]
<?php
$start = 1;
$times = 2;
$answer = array();
for ($start; $start < 11; ) {
$start++;
$answer[$start] = $start * $times;
print $answer[$start]."<br>";
}