You can make variable variable names... but I don't think you need to do that for this project.
First, consider this:
function matrix($r,$n)
{
$m1 = file("m".$n.".txt");
That will open the filename that starts with the letter "m" followed by the number you passed in. In your sample function, the variable can ALWAYS be $m1 even if it's reading from a text file called m23.txt.
Of course, if you are going to be reading mutliple files, you can easily use an array like this:
function matrix($r,$n)
{
$m = array();
$m[$n] = file("m".$n.".txt");
That way, $m[4] will have the contents of m4.txt and $m[23] will have the contents of m23.txt.
But if you really must have variable variable names, you can do something like this:
$x = 1;
$v = "m" . $x;
$$v = "this is a string";
echo $m1 . "\n\n";