<?php
$array1 = [
['page'=>'1.ru', 'title'=>'—', 'childs'=>[]],
['page'=>'3.ru', 'title'=>'—', 'childs'=>[]],
['page'=>'6.ru', 'title'=>'—', 'childs'=>[]]
];
$array2 = [
['page'=>'666.ru', 'title'=>'+', 'referer'=>'66.ru'],
['page'=>'33.ru' , 'title'=>'+', 'referer'=>'3.ru'],
['page'=>'66.ru' , 'title'=>'+', 'referer'=>'6.ru']
];
function fuckingRecursion(array $root, array &$childs){
$root['childs'] = [];
foreach($childs as $key => $child){
echo $key.'-'.$child['page'].PHP_EOL;
if($root['page'] == $child['referer']){
unset($childs[$key]);
$root['childs'][] = fuckingRecursion($child, $childs);
}
}
return $root;
}
while($root = array_pop($array1)){
var_dump(fuckingRecursion($root, $array2));
}