3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array(1,2,1,3,2,1,3,2,1,3,2,1,2,3,1,2,3); echo implode(" ", $a) . "\n"; $first = 0; $last = sizeof($a) - 1; foreach($a as $k => $v) { echo "Found $v at index $k\n"; if ($v == 1) { swap($a, $k, $first); } if ($v == 3) { swap($a, $k, $last); } } echo implode(" ", $a) . "\n"; function swap(&$arr, $k1, $k2) { echo "Swapping $k1 and $k2\n"; $tmp = $arr[$k2]; $arr[$k2] = $arr[$k1]; $arr[$k1] = $tmp; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 35
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 35
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 34
Branch analysis from position: 27
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/iIi22
function name:  (null)
number of ops:  43
compiled vars:  !0 = $a, !1 = $first, !2 = $last, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 '+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        CONCAT                                           ~7      $6, '%0A'
          6        ECHO                                                     ~7
    6     7        ASSIGN                                                   !1, 0
    7     8        COUNT                                            ~9      !0
          9        SUB                                              ~10     ~9, 1
         10        ASSIGN                                                   !2, ~10
    8    11      > FE_RESET_R                                       $12     !0, ->35
         12    > > FE_FETCH_R                                       ~13     $12, !3, ->35
         13    >   ASSIGN                                                   !4, ~13
   10    14        ROPE_INIT                                     5  ~16     'Found+'
         15        ROPE_ADD                                      1  ~16     ~16, !3
         16        ROPE_ADD                                      2  ~16     ~16, '+at+index+'
         17        ROPE_ADD                                      3  ~16     ~16, !4
         18        ROPE_END                                      4  ~15     ~16, '%0A'
         19        ECHO                                                     ~15
   11    20        IS_EQUAL                                                 !3, 1
         21      > JMPZ                                                     ~19, ->27
   12    22    >   INIT_FCALL_BY_NAME                                       'swap'
         23        SEND_VAR_EX                                              !0
         24        SEND_VAR_EX                                              !4
         25        SEND_VAR_EX                                              !1
         26        DO_FCALL                                      0          
   14    27    >   IS_EQUAL                                                 !3, 3
         28      > JMPZ                                                     ~21, ->34
   15    29    >   INIT_FCALL_BY_NAME                                       'swap'
         30        SEND_VAR_EX                                              !0
         31        SEND_VAR_EX                                              !4
         32        SEND_VAR_EX                                              !2
         33        DO_FCALL                                      0          
    8    34    > > JMP                                                      ->12
         35    >   FE_FREE                                                  $12
   19    36        INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '+'
         38        SEND_VAR                                                 !0
         39        DO_ICALL                                         $23     
         40        CONCAT                                           ~24     $23, '%0A'
         41        ECHO                                                     ~24
   27    42      > RETURN                                                   1

Function swap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iIi22
function name:  swap
number of ops:  17
compiled vars:  !0 = $arr, !1 = $k1, !2 = $k2, !3 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   23     3        ROPE_INIT                                     5  ~5      'Swapping+'
          4        ROPE_ADD                                      1  ~5      ~5, !1
          5        ROPE_ADD                                      2  ~5      ~5, '+and+'
          6        ROPE_ADD                                      3  ~5      ~5, !2
          7        ROPE_END                                      4  ~4      ~5, '%0A'
          8        ECHO                                                     ~4
   24     9        FETCH_DIM_R                                      ~8      !0, !2
         10        ASSIGN                                                   !3, ~8
   25    11        FETCH_DIM_R                                      ~11     !0, !1
         12        ASSIGN_DIM                                               !0, !2
         13        OP_DATA                                                  ~11
   26    14        ASSIGN_DIM                                               !0, !1
         15        OP_DATA                                                  !3
   27    16      > RETURN                                                   null

End of function swap

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.49 ms | 1400 KiB | 15 Q