3v4l.org

run code in 300+ PHP versions simultaneously
<?php $C = ['B' => ['S' => ['C' => []], 'H' => ['D' => []], 'G' => ['L' => []]]]; function moveArrayElementOnTop($array, $element = 'H') { $finalArray = array(); foreach ($array as $key => $values) { foreach ($values as $k => $v) { if ($k == $element) { $temp[$key][$k] = $v; unset($array[$key][$k]); } } if (isset($temp[$key])) { $finalArray[$key] = $temp[$key] + $array[$key]; } else { $finalArray[$key] = $array[$key]; } } return $finalArray; } echo "<pre>"; print_r(moveArrayElementOnTop($C)); echo "</pre>";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AVQBH
function name:  (null)
number of ops:  10
compiled vars:  !0 = $C
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   28     1        ECHO                                                     '%3Cpre%3E'
   29     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'movearrayelementontop'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
   30     8        ECHO                                                     '%3C%2Fpre%3E'
          9      > RETURN                                                   1

Function movearrayelementontop:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 30
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/AVQBH
function name:  moveArrayElementOnTop
number of ops:  33
compiled vars:  !0 = $array, !1 = $element, !2 = $finalArray, !3 = $values, !4 = $key, !5 = $v, !6 = $k, !7 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'H'
    7     2        ASSIGN                                                   !2, <array>
    9     3      > FE_RESET_R                                       $9      !0, ->30
          4    > > FE_FETCH_R                                       ~10     $9, !3, ->30
          5    >   ASSIGN                                                   !4, ~10
   10     6      > FE_RESET_R                                       $12     !3, ->17
          7    > > FE_FETCH_R                                       ~13     $12, !5, ->17
          8    >   ASSIGN                                                   !6, ~13
   11     9        IS_EQUAL                                                 !6, !1
         10      > JMPZ                                                     ~15, ->16
   12    11    >   FETCH_DIM_W                                      $16     !7, !4
         12        ASSIGN_DIM                                               $16, !6
         13        OP_DATA                                                  !5
   13    14        FETCH_DIM_UNSET                                  $18     !0, !4
         15        UNSET_DIM                                                $18, !6
   10    16    > > JMP                                                      ->7
         17    >   FE_FREE                                                  $12
   17    18        ISSET_ISEMPTY_DIM_OBJ                         0          !7, !4
         19      > JMPZ                                                     ~19, ->26
   18    20    >   FETCH_DIM_R                                      ~21     !7, !4
         21        FETCH_DIM_R                                      ~22     !0, !4
         22        ADD                                              ~23     ~21, ~22
         23        ASSIGN_DIM                                               !2, !4
         24        OP_DATA                                                  ~23
         25      > JMP                                                      ->29
   20    26    >   FETCH_DIM_R                                      ~25     !0, !4
         27        ASSIGN_DIM                                               !2, !4
         28        OP_DATA                                                  ~25
    9    29    > > JMP                                                      ->4
         30    >   FE_FREE                                                  $9
   25    31      > RETURN                                                   !2
   26    32*     > RETURN                                                   null

End of function movearrayelementontop

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
126.13 ms | 1407 KiB | 16 Q