$arr1 = [
0 => [
"Alex","12"
],
1 => [
"Jon","17"
],
2 => [
"Mary","27"
]
];
$arr2 = [
0 => [
"Alex","some"
],
1 => [
"Jon","words"
],
2 => [
"Mary","any"
],
3 => [
"Vasya","key"
]
];
$index = [];
foreach($arr1 as $row) {
$name = $row[0];
$index[$name][] = $name ;
$index[$name][] = $row;
}
foreach($arr2 as $Full){
$name = $Full[0];
if (!empty($index[$name])) {
array_splice( $Full, 1, 0, $index[$name][1][1] );
}else{
array_splice( $Full, 1, 0, 'Not Found');
}
$done = implode(",",$Full)."\n";
echo $done;
}