3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'plants'=>[ 'fruits'=>['hard'=>'coconut','juicy'=>'mango'], 'non-edible'=>'bambo' ], 'professions'=>[ 'service'=>[ 'contractors'=>['math'=>'accountant'] ], 'industry'=>'engineer' ], 'my_jobs'=>['first'=>'bartender','recent'=>'engineer'] ]; function pathFinder($target, array $source, $parentPath=''){ $results=[]; foreach($source as $k => $v){ $path = $parentPath.'/'.$k; //current path //if element is array, recurse and import found results if(is_array($v) && $result=pathFinder($target, $v,$path)){ foreach($result as $r) array_push($results,$r); } elseif($v===$target) $results[]=$path; //add any match to results } return $results; } print_r(pathFinder('engineer',$array)); print_r(pathFinder('missing data',$array));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => /professions/industry [1] => /my_jobs/recent ) Array ( )

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:
34.22 ms | 405 KiB | 5 Q