3v4l.org

run code in 500+ PHP versions simultaneously
<?php function reverseRecursive($array, $recursing = false) { foreach ($array as $key => $value) { if (is_array($value)) { $array[$key] = '(' . reverseRecursive($value, true) . ')'; } } $first = $recursing ? array_shift($array) . ',' : ''; return $first . implode(',', array_reverse($array)); } $data = '(X,1,1,3),(X,1,1,3),(X,@2,@2,@2,@2,@2,(Y,1))'; $json = preg_replace(['/[^(),]+/', '/\(/', '/\)/'], ['"$0"', '[', ']'], "($data)"); $inverse = reverseRecursive(json_decode($json)); echo $inverse;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kISpv
function name:  (null)
number of ops:  16
compiled vars:  !0 = $data, !1 = $json, !2 = $inverse
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                       !0, '%28X%2C1%2C1%2C3%29%2C%28X%2C1%2C1%2C3%29%2C%28X%2C%402%2C%402%2C%402%2C%402%2C%402%2C%28Y%2C1%29%29'
   14     1        ROPE_INIT                                         3  ~5      '%28'
          2        ROPE_ADD                                          1  ~5      ~5, !0
          3        ROPE_END                                          2  ~4      ~5, '%29'
          4        FRAMELESS_ICALL_3                preg_replace        ~7      <array>, <array>
          5        OP_DATA                                                      ~4
          6        ASSIGN                                                       !1, ~7
   15     7        INIT_FCALL                                                   'reverserecursive'
          8        INIT_FCALL                                                   'json_decode'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                             $9      
         11        SEND_VAR                                                     $9
         12        DO_FCALL                                          0  $10     
         13        ASSIGN                                                       !2, $10
   17    14        ECHO                                                         !2
   18    15      > RETURN                                                       1

Function reverserecursive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 24
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/kISpv
function name:  reverseRecursive
number of ops:  33
compiled vars:  !0 = $array, !1 = $recursing, !2 = $value, !3 = $key, !4 = $first
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      <false>
    4     2      > FE_RESET_R                                           $5      !0, ->16
          3    > > FE_FETCH_R                                           ~6      $5, !2, ->16
          4    >   ASSIGN                                                       !3, ~6
    5     5        TYPE_CHECK                                      128          !2
          6      > JMPZ                                                         ~8, ->15
    6     7    >   INIT_FCALL_BY_NAME                                           'reverseRecursive'
          8        SEND_VAR_EX                                                  !2
          9        SEND_VAL_EX                                                  <true>
         10        DO_FCALL                                          0  $10     
         11        CONCAT                                               ~11     '%28', $10
         12        CONCAT                                               ~12     ~11, '%29'
         13        ASSIGN_DIM                                                   !0, !3
         14        OP_DATA                                                      ~12
    4    15    > > JMP                                                          ->3
         16    >   FE_FREE                                                      $5
    9    17      > JMPZ                                                         !1, ->24
         18    >   INIT_FCALL                                                   'array_shift'
         19        SEND_REF                                                     !0
         20        DO_ICALL                                             $13     
         21        CONCAT                                               ~14     $13, '%2C'
         22        QM_ASSIGN                                            ~15     ~14
         23      > JMP                                                          ->25
         24    >   QM_ASSIGN                                            ~15     ''
         25    >   ASSIGN                                                       !4, ~15
   10    26        INIT_FCALL                                                   'array_reverse'
         27        SEND_VAR                                                     !0
         28        DO_ICALL                                             $17     
         29        FRAMELESS_ICALL_2                implode             ~18     '%2C', $17
         30        CONCAT                                               ~19     !4, ~18
         31      > RETURN                                                       ~19
   11    32*     > RETURN                                                       null

End of function reverserecursive

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.67 ms | 1599 KiB | 17 Q