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

Php 如何让for循环设置preg_match($patternArray[$i],$inp,$matches.$i)的变量?,php,variables,for-loop,preg-match,Php,Variables,For Loop,Preg Match,我想使用preg_match并循环它,输出应该是6$matches1-$matches6 以下代码导致: 引用错误只能传递变量 $patternArray = array($pK, $pGd, $pA, $pB, $pF, $pGF, $pAbo, $pGFK, $pGGK); for($i = 0; $i < 6; $i++) { preg_match($patternArray[$i], $input, $ucmatches . $i); }; 你可能想做这样的事情: $u

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

以下代码导致: 引用错误只能传递变量

$patternArray = array($pK, $pGd, $pA, $pB, $pF, $pGF, $pAbo, $pGFK, $pGGK);

for($i = 0; $i < 6; $i++) {
    preg_match($patternArray[$i], $input, $ucmatches . $i);
};

你可能想做这样的事情:

$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
};

尝试将匹配项添加到数组而不是级联变量:$ucmatches[$i]问题是,$ucmatches1如所愿是一个包含46个键的数组,设置为$ucmatches[1]其拆分wierdly我希望for循环为这6个preq_匹配项中的每一个创建一个多维数组!这就行了。结果如下:[patternArray[0]=>matches,patternArray[1]=>matches]问题是preq_match$pattern1,$input,$ucmatches导致$ucmatches=array1=>'abc'…40=>'xyz'我写了preq_match$pattern1,$input,$ucmatches[]它将在数组中引入另一个维度。keo它工作得非常好。我没有看到我使用preg_match而不是preg_macht_all!
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
};