<?php
$N=5; //size matrix
$pl=$N+1; //for 1st diagonal
$mn=$N-1; //for 2nd diagonal
echo 'Horizontal lines'.PHP_EOL;
for($i=1; $i<=$N*$N; $i++)
echo $i % $N == 0 ? $i.PHP_EOL : $i.' ';
echo PHP_EOL.'Vertical lines'.PHP_EOL;
for($i=1; $i<=$N; $i++) {
$vrt=$i;
for($j=1; $j<=$N; $j++) {
echo $j == $N ? $vrt.PHP_EOL : $vrt.' ';
$vrt+=$N;
}
}
echo PHP_EOL.'First diagonal'.PHP_EOL;
$frt=1;
for($i=1; $i<=$N; $i++) {
echo $frt.' ';
$frt+=$pl;
}
echo PHP_EOL.'Second diagonal'.PHP_EOL;
$scn=$N;
for($i=1; $i<=$N; $i++) {
echo $scn.' ';
$scn+=$mn;
}
PD9waHAKCiROPTU7IC8vc2l6ZSBtYXRyaXgKCiRwbD0kTisxOyAvL2ZvciAxc3QgZGlhZ29uYWwKJG1uPSROLTE7IC8vZm9yIDJuZCBkaWFnb25hbAoKZWNobyAnSG9yaXpvbnRhbCBsaW5lcycuUEhQX0VPTDsKZm9yKCRpPTE7ICRpPD0kTiokTjsgJGkrKykKZWNobyAkaSAlICROID09IDAgPyAkaS5QSFBfRU9MIDogJGkuJyAnOwoKZWNobyBQSFBfRU9MLidWZXJ0aWNhbCBsaW5lcycuUEhQX0VPTDsKZm9yKCRpPTE7ICRpPD0kTjsgJGkrKykgewogJHZydD0kaTsKICBmb3IoJGo9MTsgJGo8PSROOyAkaisrKSB7CiAgZWNobyAkaiA9PSAkTiA/ICR2cnQuUEhQX0VPTCA6ICR2cnQuJyAnOwogICR2cnQrPSROOwp9Cn0KCmVjaG8gUEhQX0VPTC4nRmlyc3QgZGlhZ29uYWwnLlBIUF9FT0w7CiRmcnQ9MTsKZm9yKCRpPTE7ICRpPD0kTjsgJGkrKykgewogZWNobyAkZnJ0LicgJzsKICRmcnQrPSRwbDsKfQoKZWNobyBQSFBfRU9MLidTZWNvbmQgZGlhZ29uYWwnLlBIUF9FT0w7CiRzY249JE47CmZvcigkaT0xOyAkaTw9JE47ICRpKyspIHsKIGVjaG8gJHNjbi4nICc7CiAkc2NuKz0kbW47Cn0KCg==