3v4l.org

run code in 300+ PHP versions simultaneously
<html> <head> </head> <style> /*li {list-style-type:none;}*/ span{cursor: pointer;background-color: yellowgreen;font-size: 20px} .hidden{display: none} </style> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <body> <?php $arr = Array( Array("cat_id" => 3, "cat_name" => "JavaScript", "parent_id" => 0, "level" => 0), Array("cat_id" => 5, "cat_name" => "Jquery", "parent_id" => 3, "level" => 1), Array("cat_id" => 6, "cat_name" => "JS高级", "parent_id" => 3, "level" => 1), Array("cat_id" => 7, "cat_name" => "JS高级更高级1", "parent_id" => 6, "level" => 3), Array("cat_id" => 8, "cat_name" => "JS高级更高级2", "parent_id" => 6, "level" => 3), Array("cat_id" => 9, "cat_name" => "JS高级更高级3", "parent_id" => 6, "level" => 3), Array("cat_id" => 4, "cat_name" => "PHP", "parent_id" => 0, "level" => 0), Array("cat_id" => 10, "cat_name" => "PHP高级1", "parent_id" => 4, "level" => 0), Array("cat_id" => 12, "cat_name" => "PHP高级2", "parent_id" => 4, "level" => 0), Array("cat_id" => 13, "cat_name" => "PHP高级3", "parent_id" => 4, "level" => 0) ); //创建树形菜单 function createTree(&$arr, $parent_id) { $hide = ""; if ($parent_id != 0) { $hide = "hidden"; } $funcName = __FUNCTION__; $ul = ""; $li = ""; for ($i = 0; $i < count($arr); $i++) { if ($arr[$i]["parent_id"] == $parent_id) { $child = $funcName($arr, $arr[$i]['cat_id']); $li .= "\r\n<li id=\"{$arr[$i]['cat_id']}\" class=\"cate\"><span>{$arr[$i]["cat_name"]}</span>{$child}</li>\r\n"; } } if ($li != "") { $ul = " <ul class=\"cate {$hide}\">{$li}</ul> "; } return $ul; } echo createTree($arr, 0); ?> </body> <script> (function() { $(".cate").hover(function() { $(this).children("ul").show() }, function() { $(this).children("ul").hide() }) })() </script> </html>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PWqDs
function name:  (null)
number of ops:  9
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   ECHO                                                     '%3Chtml%3E%0A++++%3Chead%3E%0A++++%3C%2Fhead%3E%0A++++%3Cstyle%3E%0A++++++++%2F%2Ali+%7Blist-style-type%3Anone%3B%7D%2A%2F%0A++++++++span%7Bcursor%3A+pointer%3Bbackground-color%3A+yellowgreen%3Bfont-size%3A+20px%7D%0A++++++++.hidden%7Bdisplay%3A+none%7D%0A++++%3C%2Fstyle%3E%0A++++%3Cscript+src%3D%22%2F%2Fcode.jquery.com%2Fjquery-1.11.0.min.js%22%3E%3C%2Fscript%3E%0A++++%3Cbody%3E%0A++++++++'
   12     1        ASSIGN                                                   !0, <array>
   50     2        INIT_FCALL                                               'createtree'
          3        SEND_REF                                                 !0
          4        SEND_VAL                                                 0
          5        DO_FCALL                                      0  $2      
          6        ECHO                                                     $2
   52     7        ECHO                                                     '++++%3C%2Fbody%3E%0A++++%3Cscript%3E%0A++++++++%28function%28%29+%7B%0A++++++++++++%24%28%22.cate%22%29.hover%28function%28%29+%7B%0A++++++++++++++++%24%28this%29.children%28%22ul%22%29.show%28%29%0A++++++++++++%7D%2C+function%28%29+%7B%0A++++++++++++++++%24%28this%29.children%28%22ul%22%29.hide%28%29%0A++++++++++++%7D%29%0A++++++++%7D%29%28%29%0A++++%3C%2Fscript%3E%0A%3C%2Fhtml%3E'
   62     8      > RETURN                                                   1

Function createtree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 11
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 47
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 35
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 11
Branch analysis from position: 39
Branch analysis from position: 11
Branch analysis from position: 35
Branch analysis from position: 6
filename:       /in/PWqDs
function name:  createTree
number of ops:  49
compiled vars:  !0 = $arr, !1 = $parent_id, !2 = $hide, !3 = $funcName, !4 = $ul, !5 = $li, !6 = $i, !7 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        ASSIGN                                                   !2, ''
   28     3        IS_NOT_EQUAL                                             !1, 0
          4      > JMPZ                                                     ~9, ->6
   29     5    >   ASSIGN                                                   !2, 'hidden'
   31     6    >   ASSIGN                                                   !3, 'createTree'
   32     7        ASSIGN                                                   !4, ''
   33     8        ASSIGN                                                   !5, ''
   34     9        ASSIGN                                                   !6, 0
         10      > JMP                                                      ->36
   35    11    >   FETCH_DIM_R                                      ~15     !0, !6
         12        FETCH_DIM_R                                      ~16     ~15, 'parent_id'
         13        IS_EQUAL                                                 !1, ~16
         14      > JMPZ                                                     ~17, ->35
   36    15    >   INIT_DYNAMIC_CALL                                        !3
         16        SEND_VAR_EX                                              !0
         17        CHECK_FUNC_ARG                                           
         18        FETCH_DIM_FUNC_ARG                               $18     !0, !6
         19        FETCH_DIM_FUNC_ARG                               $19     $18, 'cat_id'
         20        SEND_FUNC_ARG                                            $19
         21        DO_FCALL                                      0  $20     
         22        ASSIGN                                                   !7, $20
   37    23        ROPE_INIT                                     7  ~27     '%0D%0A%3Cli+id%3D%22'
         24        FETCH_DIM_R                                      ~22     !0, !6
         25        FETCH_DIM_R                                      ~23     ~22, 'cat_id'
         26        ROPE_ADD                                      1  ~27     ~27, ~23
         27        ROPE_ADD                                      2  ~27     ~27, '%22+class%3D%22cate%22%3E%3Cspan%3E'
         28        FETCH_DIM_R                                      ~24     !0, !6
         29        FETCH_DIM_R                                      ~25     ~24, 'cat_name'
         30        ROPE_ADD                                      3  ~27     ~27, ~25
         31        ROPE_ADD                                      4  ~27     ~27, '%3C%2Fspan%3E'
         32        ROPE_ADD                                      5  ~27     ~27, !7
         33        ROPE_END                                      6  ~26     ~27, '%3C%2Fli%3E%0D%0A'
         34        ASSIGN_OP                                     8          !5, ~26
   34    35    >   PRE_INC                                                  !6
         36    >   COUNT                                            ~33     !0
         37        IS_SMALLER                                               !6, ~33
         38      > JMPNZ                                                    ~34, ->11
   40    39    >   IS_NOT_EQUAL                                             !5, ''
         40      > JMPZ                                                     ~35, ->47
   41    41    >   ROPE_INIT                                     5  ~37     '%0A%0A%3Cul+class%3D%22cate+'
   43    42        ROPE_ADD                                      1  ~37     ~37, !2
         43        ROPE_ADD                                      2  ~37     ~37, '%22%3E'
         44        ROPE_ADD                                      3  ~37     ~37, !5
         45        ROPE_END                                      4  ~36     ~37, '%3C%2Ful%3E%0A%0A'
   41    46        ASSIGN                                                   !4, ~36
   47    47    > > RETURN                                                   !4
   48    48*     > RETURN                                                   null

End of function createtree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.44 ms | 1403 KiB | 14 Q