3v4l.org

run code in 300+ 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:  19
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        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 <array>
          4        ROPE_INIT                                     3  ~5      '%28'
          5        ROPE_ADD                                      1  ~5      ~5, !0
          6        ROPE_END                                      2  ~4      ~5, '%29'
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !1, $7
   15    10        INIT_FCALL                                               'reverserecursive'
         11        INIT_FCALL                                               'json_decode'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $9      
         14        SEND_VAR                                                 $9
         15        DO_FCALL                                      0  $10     
         16        ASSIGN                                                   !2, $10
   17    17        ECHO                                                     !2
   18    18      > 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:  36
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                                               'implode'
         27        SEND_VAL                                                 '%2C'
         28        INIT_FCALL                                               'array_reverse'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $17     
         31        SEND_VAR                                                 $17
         32        DO_ICALL                                         $18     
         33        CONCAT                                           ~19     !4, $18
         34      > RETURN                                                   ~19
   11    35*     > RETURN                                                   null

End of function reverserecursive

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.69 ms | 1017 KiB | 19 Q