0

如何组合以下数组?例如第一个$match和第一个$register之后,以回显数组

$matches = array();
$registration = array();

preg_match_all('#(69\d{8}|21\d{8}|22\d{8}|23\d{8})#', $str2, $matches); 
preg_match_all('!<td class="registration">(.*?)</td>!is', $str2, $registration);


foreach ($matches[1] as $match) {
    echo $match.'<br>';
}
foreach ($registration[1] as $register) {
    echo $register.'<br>';
}
4

4 回答 4

3

试试这个例子:

foreach (array_combine($matches[1], $registrations[1]) as $matche => $registration) {
        echo $matche." - ".$registration;
    }

和您的另一篇文章:foreach 循环中的两个数组

于 2013-09-26T15:57:14.663 回答
1

您可以遍历一个并从另一个数组中获取相同的键。

foreach ($matches[1] as $key=>$match) {
    $register = $register[1][$key];

    echo $match.' '.$register.'<br>';
}
于 2013-09-26T15:55:51.747 回答
1

可能这会帮助你

$array = array();
foreach ($matches[1] as $key => $match) {

     $array[] = array($match, $register[1][$i]);
}
var_dump($array);
于 2013-09-26T15:58:16.763 回答
1

你可以使用array_merge()函数。

$combinedArray = array_merge($matches, $registration);

foreach ($combinedArray as $row) {

}

https://codeupweb.wordpress.com/2017/07/14/merging-and-sorting-arrays-in-php/

于 2017-07-25T08:01:36.057 回答