You already have the answer. This one is only to explain better than in comments your assumption error.
$1 is not a result of first parameter, it is a placeholder used only by preg_replace itself. Your use invoke also the commands precedence.
In other words, if you try this code:
$text = 'Lorem test8 Dolor';
function test( $arg ) { echo $arg.PHP_EOL; }
$text = preg_replace('/test([0-9]+)/i', test("$1"), $text);
echo $text;
You obtain this output:
$1
Lorem Dolor
As you can see, first argument is evaluated, then the result is used by preg_replace: test() function receive literally $1 (and in the same way your array), not the 8 retrieved by preg_replace; then preg_replace replace matched substring by value returned in second argument: in above case test() returns nothing, so the replacement is nothing.
With this code:
function test() { return '[$1]'; }
$text = preg_replace('/test([0-9]+)/i', test(), $text);
The resulting string is:
Lorem [8] Dolor
because test() returns [$1] and it can be used by preg_replace to perform the replacement.
In your specific case, the replacement happen only if you have a scenario like this one:
$array["$1"] = 'Ipsum';
$text = preg_replace('/test([0-9]+)/i', $array["$1"], $text);
The final text is:
Lorem Ipsum Dolor
This is not your desired result, but — as mentioned earlier — you already have the answer...
preg_replace_callback()and pass the array viause()to it,