3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'Id' => 1, 'Title' => 'Some Text1', 'Children' => [ [ 'Id' => 22, 'Title' => 'Some Text22', 'Children' => [ [ 'Id' => 333, 'Title' => 'Some Text333' ], [ 'Id' => 334, 'Title' => 'Some Text334', 'Children' => [ [ 'Id' => 4444, 'Title' => 'Some Text4443' ] ] ] ] ], [ 'Id' => 23, 'Title' => 'Some Text23', 'Children' => [ [ 'Id' => 335, 'Title' => 'Some Text335' ] ] ] ] ], [ 'Id' => 2, 'Title' => 'Some Text2', ] ]; function pathFinder(array $array, string $find, string $path = ''): array { $paths = []; foreach ($array as $item) { $currentPath = $path . ($path ? ' -> ' : '') . $item['Id']; if (str_contains($item['Title'], $find)) { $paths[] = $currentPath; } if (isset($item['Children'])) { array_push( $paths, ...pathFinder($item['Children'], $find, $currentPath) ); } } return $paths; } var_export( pathFinder($array, 'Some Text335') );
Output for git.master, git.master_jit
array ( 0 => '1 -> 23 -> 335', )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
59.14 ms | 405 KiB | 5 Q