3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a= array ( 1 => 0, 2 => 1, 3 => 2, 4 => 3, 5 => 1, 6 => 0 ); class Menu extends CI_Model { public function __construct() { parent::__construct(); } public function menu_array($parent = 0) { $items = array(); $this->db->where('parent', $parent); $results = $this->db->get('os_menu')->result(); foreach($results as $result) { $child_array = $this->menu_array($result->id); if(sizeof($child_array) == 0) { array_push($items, $result); } else { array_push($items, array($result, $child_array)); } } return $items; } public function show_menu_array($array){ $output = '<ul>'; foreach ($array as $key => $mixedValue) { if (is_array($mixedValue)) { $output .= '<li>' . $this->show_menu_array($mixedValue) . '</li>'; } else { $output .= '<li>' . $mixedValue->name . '</li>'; } } $output .= '</ul>'; return $output; } $menu = new Menu(); $menu_array = $menu->menu_array(); echo $menu->show_menu_array($menu_array);
Output for 5.4.0 - 5.4.29
Parse error: syntax error, unexpected '$menu' (T_VARIABLE), expecting function (T_FUNCTION) in /in/t5nIN on line 51
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /in/t5nIN on line 51
Process exited with code 255.

preferences:
205.53 ms | 1395 KiB | 66 Q