如何组合以下数组?例如,第一个$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>';
}
答案 0 :(得分:3)
试试这个例子:
foreach (array_combine($matches[1], $registrations[1]) as $matche => $registration) {
echo $matche." - ".$registration;
}
和其他帖子一样:Two arrays in foreach loop
答案 1 :(得分:1)
你可以循环访问一个并从另一个数组中获取相同的密钥。
foreach ($matches[1] as $key=>$match) {
$register = $register[1][$key];
echo $match.' '.$register.'<br>';
}
答案 2 :(得分:1)
可能会帮助你
$array = array();
foreach ($matches[1] as $key => $match) {
$array[] = array($match, $register[1][$i]);
}
var_dump($array);
答案 3 :(得分: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/