foreach($array1 as $key => $ar) {
foreach($array2 as $sm) {
if( $ar['name1'] == $sm['name1'] || $ar['name2'] == $sm['name2'] ) {
#code
}
}
}
t2.avto_id = t1.id
t2.avto_id = t1.id , t2.avto_id = t1.second_id