Mar 28th, 2008, 12:07 PM
|
#3
|
|
King of Portal
Join Date: Sep 2005
Posts: 403
Rep Power: 3 
|
Re: help for (for)
This is a bit more memory intensive and slower as well, but I like how it works: <?php // Get matrix size $rowSize = $_POST['rw']; $colSize = $_POST['col']; ?> <?php // Construct matrix $shiftable = array(); for($i = 0; $i < $rowSize; $i++){ $temp = array(); for($j = 0; $j < $colSize; $j++){ array_push($temp, $j); } array_push($shiftable, $temp); shiftRow($shiftable, $i, $i); // Shift matrix accordingly } ?> <pre> <?php // Print matrix foreach($shiftable as $row){ foreach($row as $j => $value){ echo str_pad($value, 2, ' ', STR_PAD_LEFT); } echo "\n"; } ?> </pre> <?php // Row shifting function function shiftRow(&$dArray, $shiftRow, $shiftAmount){ for($i = 0; $i < $shiftAmount; $i++){ array_push($dArray[$shiftRow], array_shift($dArray[$shiftRow])); } } ?>
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
|
|
|