<?php
$matrice=array();
$righe=4;
$colonne=4;
$somma=0;
for($r=0; $r<$righe; $r++){
for($c=0; $c<$colonne; $c++){
$val_cella=rand(1,100);
$matrice[$r][$c]=$val_cella;
if($r==$c){
$somma+=$val_cella;
}
}
}
echo "<pre>";
var_dump ($matrice);
echo "somma diagonale $somma";
echo "</pre>";
?>