3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = json_decode('{ "Group1": { "Blue": { "Round": [ "Harold", "Arthur", "Tom" ] }, "Green": { "Round": [ "Harold" ], "Circle": [ "Todd", "Mike" ] } }, "Group2": { "Blue": { "Round": [ "Peter" ] } } }', true); function traverse_array($array,$key="",$prev="",&$final_op=array()) { if(is_array($array)) { $prev .= $key." - "; foreach ($array as $key => $value) { traverse_array($value,$key,$prev,$final_op); } } else { $prev =trim($prev," - "); $final_op[$prev][]=$array; } return $final_op; } $data = traverse_array($obj); foreach ($data as $key => $value) { echo $key." (".implode(",", $value).")"; echo PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
Group1 - Blue - Round (Harold,Arthur,Tom) Group1 - Green - Round (Harold) Group1 - Green - Circle (Todd,Mike) Group2 - Blue - Round (Peter)

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:
60.25 ms | 401 KiB | 8 Q