PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function render($num, $strLength, $result, $hor, $ver, $currentNum, $horisontal = true, $reverse = false) { foreach(range(1, $strLength) as $b) { if ($horisontal && !$reverse) { $result[$ver][$hor] = $currentNum; if ($b < $strLength) $hor++; } elseif ($horisontal && $reverse) { --$hor; $result[$ver][$hor] = $currentNum; } elseif (!$horisontal && $reverse) { $ver--; $result[$ver][$hor] = $currentNum; if ($b === $strLength) $hor++; } elseif (!$horisontal && !$reverse) { $ver++; $result[$ver][$hor] = $currentNum; } $currentNum++; } $horisontalNext = $horisontal ? false : true; $reverseNext = $reverse; if (!$horisontal && $reverse) $reverseNext = false; if (!$horisontal && !$reverse) $reverseNext = true; return ($currentNum > $num * $num) ? $result : render( $num, ($horisontal ? $strLength - 1 : $strLength), $result, $hor, $ver, $currentNum, $horisontalNext, $reverseNext ); } foreach (render(6, 6, [], 0, 0, 1) as $i) { ksort($i); foreach ($i as $j) echo ' ' . $j; echo "\n"; }
Show:  
Copy Clear