爆炸a:b到a:c php

I have 2 files for example

file1.txt and file2.txt

file1.txt contains for example following content:

a:b
markus:lanz
peter:heinrichs
lach:schnell

and file2.txt contains for example following content (the 2nd explode of the file1.txt)

b:c
lanz:hallo
heinrichs:gruss
schnell:langsam

so i want to have following output in php:

a:c
markus:hallo
peter:gruss
lach:langsam

how is this possible?

first explode the first and then search or how?

thanks

my current code is following:

<?php
$file1 = 'a:b
markus:lanz
peter:heinrichs
lach:schnell';

$file2 = '
lanz:hallo
heinrichs:gruss
b:c
test:notest
schnell:langsam';




  $array = explode(":", $file1);

  for($i=0; $i < count($array); $i++) {


  $array = explode(":", $file1);

 $pattan = $array[$i];
  $pattern = '=
'. $pattan .':(.*)
=sUm'; 
  $result = preg_match($pattern, $file2, $subpattern); 

 echo "<br>";
  echo $array[$i];
  $first = $array[$i];
  echo "<br>";
  }



  $pattern = '=
'. $first .':(.*)
=sUm'; 
  $result = preg_match($pattern, $file2, $subpattern); 
var_dump($subpattern); 

?>

what am i making wrong?

What do you think about this :

$file1="a:b
markus:lanz
peter:heinrichs
lach:schnell";

$file2="b:c
lanz:hallo
heinrichs:gruss
schnell:langsam";

$a1 = explode("
",$file1);
$a2 = explode("
",$file2);

if(count($a1) != count($a2)) die("files don't match!");

$final=array();
foreach($a1 as $k=>$line){
   $l1 = explode(":",$line);
   $l2 = explode(":",$a2[$k]);
   $final[]=$l1[0].':'.$l2[1];
}
print_r($final);

I would use the following approach:

// load your two files into arrays using file() and explode each line on ':'
foreach ([1,2] as $n) {
   $files[$n] = array_map(function($x){ return explode(':', trim($x));}, file("file$n.txt"));
}

// with file1, fill the output array with 'a' values using 'b' as the key to output
foreach ($files[1] as $ab) {
    $output[$ab[1]]['a'] = $ab[0];
}

// with file2, fill the output array with 'c' values, also using 'b' as the key
foreach ($files[2] as $bc) {
    $output[$bc[0]]['c'] = $bc[1];
}

// remove any elements that do not have count 2 (i.e. both a and c values)
$output = array_filter($output, function ($x) { return count($x) == 2; });