shamuraq Posted January 22, 2012 Share Posted January 22, 2012 Hi all, I'm trying to list the possible combinations in fraction from 1/1 + 1/1 until 9/9 + 9/9. So i came up with this <?php //numbers of combination for w/x + y/z $num1=1; $den1=1; $num2=1; $den2=1; $row=1; for($w=0; $w<9; $w++){ echo $row.') '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; $num1=$num1+1; for($x=0; $x<9; $x++){ echo $row.') '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; $den1=$den1+1; for($y=0; $y<9; $y++){ echo $row.') '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; $num2=$num2+1; for($z=0; $z<9; $z++){ echo $row.') '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; $den2=$den2+1; } } } } ?> The problem is it parse all the way to 7380) 10/82 + 730/6561. Where did it go wrong? Thanx in advance... Quote Link to comment https://forums.phpfreaks.com/topic/255504-help-with-listing-combinations-using-for-loop/ Share on other sites More sharing options...
sasa Posted January 23, 2012 Share Posted January 23, 2012 just do <?php //numbers of combination for w/x + y/z $num1=1; $den1=1; $num2=1; $den2=1; $row=1; for($num1=1; $num1<=9; $num1++){ for($den1=1; $den1<=9; $den1++){ for($num2=1; $num2<=9; $num2++){ for($den2=1; $den2<=9; $den2++){ echo $row.'. ) '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255504-help-with-listing-combinations-using-for-loop/#findComment-1310331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.