looping problem
Posted: Sun Aug 14, 2011 6:59 pm
Hi,
Strange this but
I would have expected this output
but get this shorter output
How come I'm missing 2/3 my expected results?
Many thanks
GW
Strange this but
Code: Select all
<?php
for ($i=1; $i<=4; $i++) {
for ($j=1; $j<=4; $j++) {
for ($k=1; $k<=4; $k++) {
if (($i == $j) || ($i == $k) || ($j == $k)) { break; } # don't want duplicate numbers
echo $i." ".$j." ".$k." "."<br>";
}
}
}
?>
Code: Select all
1 2 3
1 2 4
1 3 2
1 3 4
1 4 2
1 4 3
2 1 3
2 1 4
2 3 1
2 3 4
2 4 1
2 4 3
3 1 2
3 1 4
3 2 1
3 2 4
3 4 1
3 4 2
4 1 2
4 1 3
4 2 1
4 2 3
4 3 1
4 3 2
Code: Select all
2 3 1
2 4 1
3 2 1
3 4 1
3 4 2
4 2 1
4 3 1
4 3 2
Many thanks
GW