Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $row = 4;
- $start = 1;
- $i = 1;
- for ($i; $i <= $row; $i++)
- {
- if($i % 2 == 0)
- {
- $first = $start + 2;
- $sec = $start + 1;
- printf("%d %d %d <br>", $first, $sec, $start);
- $start = $start + 3;
- }else{
- printf("%d %d %d<br>", $start, $start+1, $start+2);
- $start = $start + 3;
- }
- }
- // Output
- // 1 2 3
- // 6 5 4
- // 7 8 9
- // 12 11 10
- Alternative
- $rows=4;
- $cols=10; // Any Numbers Of Column
- $count=1;
- for($i=1; $i<=$rows; $i++)
- {
- if($i%2==0){
- $count=$count+$cols-1;
- }
- for($j=$cols; $j>=1; $j--)
- {
- echo $count." ";
- if($i%2==0)
- $count--;
- else
- $count++;
- }
- if($i%2==0){
- $count=$count+$cols+1;
- }
- echo "<br>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement