3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = array ( 0 => array ( 'id' => '1', 'p_pag' => '0', 'link' => 'Contact', 'children' => array ( 0 => array ( 'id' => '2', 'p_pag' => '1', 'link' => 'Contact-County', 'children' => array ( 0 => array ( 'id' => '3', 'p_pag' => '2', 'link' => 'Contact-Town-1', 'children' => array ( ), ), ), ), ), ), ); function getLinkPathById(array $array, string $toId): ?string { foreach ($array as $row) { if ( $row['id'] === $toId || ($deeper = getLinkPathById($row['children'], $toId)) ) { return '/' . $row['link'] . ($deeper ?? null); } } return null; } echo "1: " . getLinkPathById($array, 1) . PHP_EOL; echo "2: " . getLinkPathById($array, 2) . PHP_EOL; echo "3: " . getLinkPathById($array, 3) . PHP_EOL; echo "4: " . getLinkPathById($array, 4);
Output for git.master, git.master_jit, rfc.property-hooks
1: /Contact 2: /Contact/Contact-County 3: /Contact/Contact-County/Contact-Town-1 4:

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:
52.05 ms | 1258 KiB | 4 Q