3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<? $navigation = array( array( "title" => "Overzicht", "enabled" => 0, "submenu" => array( array( "title" => "Dashboard", "url" => "dashboard/", "module" => "Home", "icon" => "icon-home", "userlevel" => 0, "enabled" => 1 ), array( "title" => "Mijn statistieken", "url" => "user/stats/", "module" => "User", "icon" => "icon-stats", "userlevel" => 60, "enabled" => 1 ) ) ), array( "title" => "Acties", "enabled" => 1, "submenu" => array( array( "title" => "Alle acties", "url" => "action/", "module" => "Action", "icon" => "icon-list-alt", "userlevel" => 0, "enabled" => 0 ), array( "title" => "Mijn acties", "url" => "action/:user_id/", "module" => "Action", "icon" => "icon-list", "userlevel" => 60, "enabled" => 1 ), array( "title" => "Nieuwe actie", "url" => "new/", "module" => "Action", "icon" => "icon-plus", "userlevel" => 80, "enabled" => 1 ) ) ) ); $filterFunc = function($item) use (&$filterFunc) { if (!$v["enabled"]) return false; if (isset($v["userlevel"])) { if (($v["userlevel"] > 60)) return false; } if (isset($v["submenu"])) { return array_filter($v["submenu"], $filterFunc); } return true; }; $navigation = array_filter($navigation, $filterFunc); var_dump($navigation);
Output for 5.4.0 - 7.1.0
Notice: Undefined variable: v in /in/Xk9V8 on line 59 Notice: Undefined variable: v in /in/Xk9V8 on line 59 array(0) { }
Output for 4.3.0 - 5.3.29
<? $navigation = array( array( "title" => "Overzicht", "enabled" => 0, "submenu" => array( array( "title" => "Dashboard", "url" => "dashboard/", "module" => "Home", "icon" => "icon-home", "userlevel" => 0, "enabled" => 1 ), array( "title" => "Mijn statistieken", "url" => "user/stats/", "module" => "User", "icon" => "icon-stats", "userlevel" => 60, "enabled" => 1 ) ) ), array( "title" => "Acties", "enabled" => 1, "submenu" => array( array( "title" => "Alle acties", "url" => "action/", "module" => "Action", "icon" => "icon-list-alt", "userlevel" => 0, "enabled" => 0 ), array( "title" => "Mijn acties", "url" => "action/:user_id/", "module" => "Action", "icon" => "icon-list", "userlevel" => 60, "enabled" => 1 ), array( "title" => "Nieuwe actie", "url" => "new/", "module" => "Action", "icon" => "icon-plus", "userlevel" => 80, "enabled" => 1 ) ) ) ); $filterFunc = function($item) use (&$filterFunc) { if (!$v["enabled"]) return false; if (isset($v["userlevel"])) { if (($v["userlevel"] > 60)) return false; } if (isset($v["submenu"])) { return array_filter($v["submenu"], $filterFunc); } return true; }; $navigation = array_filter($navigation, $filterFunc); var_dump($navigation);