$matriz lo armás con la base de datos... estás iterando las rows?
Código PHP:
while ($row = mysql_fetch_assoc($query))
$matriz[md5($row)]=array('identificador'=>md5($id),'referencia'=>$ro w['REF'],'cantidad'=>$qty,'tipo'=>$row['TIPO'],'producto'=>$row['MODELO'],'marca'=>$row['MARCA']);