如何让for循环设置preg_match($patternArray[$i], $inp, $matches)的变量.我


How to let a for loop set the variable of preg_match($patternArray[$i], $inp, $matches.$i )?

我想使用preg_match并循环它,输出应该是6 $matches1 - $matches6

下面的代码导致:只有变量可以通过引用传递Error

$patternArray = array($pK, $pGd, $pA, $pB, $pF, $pGF, $pAbo, $pGFK, $pGGK);
for($i = 0; $i < 6; $i++) {
    preg_match($patternArray[$i], $input, $ucmatches . $i);
};

I already tried

for($i=1;$i<6;$i++){
$m = ${'matches'.$i};
preg_match($patternArray[$i], $input, $m);
};

导致

PHP Notice:  Undefined variable: matches1 in new.php on line 21
PHP Notice:  Undefined variable: matches2 in new.php on line 21
PHP Notice:  Undefined variable: matches3 in new.php on line 21
PHP Notice:  Undefined variable: matches4 in new.php on line 21
PHP Notice:  Undefined variable: matches5 in new.php on line 21
PHP Notice:  Undefined variable: matches in new.php on line 26
NULL

您可能正在尝试这样做:

$ucmatches = array(); // not necessary but good practice
for($i=0; $i<6; $i++){
    preg_match($patternArray[$i], $input, $ucmatches[$i]);
    preg_match($patternArray[$i], $input, $ucmatches[]); // no need to force indexes
};