3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function createPageLlink($name,$id,$alias,$catalias){ $link = $id . "/" . $alias . "/" . $catalias; return '<a href="' . htmlentities($link,ENT_COMPAT,"UTF-8") . '">' . htmlentities($name,ENT_COMPAT,"UTF-8") .'</a>'; } $source=json_decode('[ {"parentTitle":"Winner 2009","catTitle":"Mas Muster","title":"drm202","id":"5","alias":"item1","catalias":"first"}, {"parentTitle":"Winner 2009","catTitle":"Mas Muster","title":"drm202","id":"2","alias":"item2","catalias":"first"}, {"parentTitle":"Winner 2011","catTitle":"Josh Frank","title":"A bird in the cage","id":"6","alias":"item3","catalias":"second"}, {"parentTitle":"Winner 2011","catTitle":"Josh Frank","title":"cue & repeat","id":"7","alias":"item4","catalias":"third"}]'); $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][]=array("title"=>$v->title,"id"=>$v->id,"alias"=>$v->alias,"catalias"=>$v->catalias); }); 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>" . createPageLlink ($v["title"],$v["id"],$v["alias"],$v["catalias"] ) . "</li>\n"; } echo "</ul>\n</li>"; } echo "</ul>\n</li>"; } echo "</ul>";
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [Winner 2009] => Array ( [Mas Muster] => Array ( [0] => Array ( [title] => drm202 [id] => 5 [alias] => item1 [catalias] => first ) [1] => Array ( [title] => drm202 [id] => 2 [alias] => item2 [catalias] => first ) ) ) [Winner 2011] => Array ( [Josh Frank] => Array ( [0] => Array ( [title] => A bird in the cage [id] => 6 [alias] => item3 [catalias] => second ) [1] => Array ( [title] => cue & repeat [id] => 7 [alias] => item4 [catalias] => third ) ) ) ) <ul><li>Winner 2009 <ul><li>Mas Muster <ul><li><a href="5/item1/first">drm202</a></li> <li><a href="2/item2/first">drm202</a></li> </ul> </li></ul> </li><li>Winner 2011 <ul><li>Josh Frank <ul><li><a href="6/item3/second">A bird in the cage</a></li> <li><a href="7/item4/third">cue &amp; repeat</a></li> </ul> </li></ul> </li></ul>
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/leV71 on line 16
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/leV71 on line 16
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/leV71 on line 16
Process exited with code 255.