Guest User

Untitled

a guest
Jun 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. $test = array();
  2.  
  3. // initialize the array with random values
  4. for($i=0; $i<5; $i++)
  5. {
  6.     for ($j=0; $j < 5; $j++) {
  7.         $test[$i][$j] = rand(0, 10);
  8.     }
  9. }
  10.  
  11. displayArray($test); // custom function I wrote to display the array in a HTML table
  12.  
  13.  
  14. //x = rows, y = columns
  15.  
  16. for ($x = 0; $x<5; $x++) // loop over each row
  17. {
  18.     if($x == 5-1) // if this is the LAST row
  19.         continue; // skip this iteration
  20.    
  21.     $y = $x+1; // initialise Y to the row numer + offset 1
  22.     // i.e. this will point to the cells on the RIGHT of the diagonal
  23.  
  24.     // display value
  25.     echo '$test['.$x.']['.$y.'] = '.$test[$x][$y] .'<br/>';
  26. }
Add Comment
Please, Sign In to add comment