Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?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)); }
Copy Clear