How can you treat groups captured in $1 -$9 as variables in PHP?

To treat groups captured in $1 - $9 as variables in PHP, you can use the preg_match function with capturing groups in regular expressions. The captured groups can be accessed using $1, $2, $3, and so on in the order they appear in the regular expression pattern.

$string = "Hello World";
if (preg_match('/(Hello) (World)/', $string, $matches)) {
    $firstWord = $matches[1];
    $secondWord = $matches[2];
    echo $firstWord; // Output: Hello
    echo $secondWord; // Output: World
}