Se consideri la matrice come un array di array, è presto detto...
Codice PHP:
// definisci $numero_righe e $numero_colonne della tua matrice

for($k=0;k<$numero_righe;k++) {
  for (
$i 0$i $numero_colonne$i++) {
    if (!
array_key_exists($i,$matrice[$k]) )
       
$matrice[$k][$i] = 0;
  }

Fammi sapere