3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $source=json_decode('[{"parentTitle":"Winner 2009","catTitle":"Mas Muster","title":"drm202"},{"parentTitle":"Winner 2009","catTitle":"Mas Muster","title":"drm202"},{"parentTitle":"Winner 2011","catTitle":"Josh Frank","title":"A bird in the cage"},{"parentTitle":"Winner 2011","catTitle":"Josh Frank","title":"cue & repeat"}]'); $result=array(); array_walk($source,function($v,$i)use(&$result){ if(!isset($result[$v->parentTitle])) $result[$v->parentTitle]=array(); if(!isset($result[$v->parentTitle][$v->catTitle])) $result[$v->parentTitle][$v->catTitle]=array(); if(!in_array($v->title,$result[$v->parentTitle][$v->catTitle])) $result[$v->parentTitle][$v->catTitle][]=$v->title; }); print_r($result); // just to debug echo "<ul>"; foreach($result as $key=>$sub){ echo "<li>".htmlentities($key,ENT_COMPAT,"UTF-8"); echo "\n<ul>"; foreach($sub as $k=>$s){ echo "<li>".htmlentities($k,ENT_COMPAT,"UTF-8"); echo "\n<ul>"; foreach($s as $i=>$v){ echo "<li>".htmlentities($v,ENT_COMPAT,"UTF-8")."</li>\n"; } echo "</ul>\n</li>"; } echo "</ul>\n</li>"; } echo "</ul>";
Output for 5.3.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Array ( [Winner 2009] => Array ( [Mas Muster] => Array ( [0] => drm202 ) ) [Winner 2011] => Array ( [Josh Frank] => Array ( [0] => A bird in the cage [1] => cue & repeat ) ) ) <ul><li>Winner 2009 <ul><li>Mas Muster <ul><li>drm202</li> </ul> </li></ul> </li><li>Winner 2011 <ul><li>Josh Frank <ul><li>A bird in the cage</li> <li>cue &amp; repeat</li> </ul> </li></ul> </li></ul>
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/sQ59p on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/sQ59p on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/sQ59p on line 4
Process exited with code 255.