3v4l.org

run code in 500+ PHP versions simultaneously
<?php /** * @deprecated */ function flipA(&$arr) { for ($i = 0; $i < count($arr); $i++) { $tmp = $arr[$i]; $arr[$i] = $arr[count($arr) - $i - 1]; $arr[count($arr) - $i - 1] = $tmp; } return $arr; } $arr = [1, 2, 3, 4, 5]; var_dump(flipA($arr)); /** * Flip array function (new) * @param array $arr * @return array */ function flipArray(array $arr): array { $arrayLength = count($arr); if(!$arrayLength) { return []; } for ($i = 0; $i < $arrayLength / 2; $i++) { swapArrayElements($arr, $i, $arrayLength - $i - 1); } return $arr; } /** * Swap 2 array elements * @param array $arr * @param int $i - index of first element * @param int $j - index of second element */ function swapArrayElements(&$arr, $i, $j) { $tmp = $arr[$i]; $arr[$i] = $arr[$j]; $arr[$j] = $tmp; } $arr2 = [1, 2, 3, 4, 5]; var_dump(flipArray($arr2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZL6eU
function name:  (null)
number of ops:  15
compiled vars:  !0 = $arr, !1 = $arr2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                       !0, <array>
   17     1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'flipa'
          3        SEND_REF                                                     !0
          4        DO_FCALL                                          0  $3      
          5        SEND_VAR                                                     $3
          6        DO_ICALL                                                     
   50     7        ASSIGN                                                       !1, <array>
   51     8        INIT_FCALL                                                   'var_dump'
          9        INIT_FCALL                                                   'fliparray'
         10        SEND_VAR                                                     !1
         11        DO_FCALL                                          0  $6      
         12        SEND_VAR                                                     $6
         13        DO_ICALL                                                     
         14      > RETURN                                                       1

Function flipa:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 3
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 3
Branch analysis from position: 20
Branch analysis from position: 3
filename:       /in/ZL6eU
function name:  flipA
number of ops:  22
compiled vars:  !0 = $arr, !1 = $i, !2 = $tmp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
    8     1        ASSIGN                                                       !1, 0
          2      > JMP                                                          ->17
    9     3    >   FETCH_DIM_R                                          ~4      !0, !1
          4        ASSIGN                                                       !2, ~4
   10     5        COUNT                                                ~7      !0
          6        SUB                                                  ~8      ~7, !1
          7        SUB                                                  ~9      ~8, 1
          8        FETCH_DIM_R                                          ~10     !0, ~9
          9        ASSIGN_DIM                                                   !0, !1
         10        OP_DATA                                                      ~10
   11    11        COUNT                                                ~11     !0
         12        SUB                                                  ~12     ~11, !1
         13        SUB                                                  ~13     ~12, 1
         14        ASSIGN_DIM                                                   !0, ~13
         15        OP_DATA                                                      !2
    8    16        PRE_INC                                                      !1
         17    >   COUNT                                                ~16     !0
         18        IS_SMALLER                                                   !1, ~16
         19      > JMPNZ                                                        ~17, ->3
   13    20    > > RETURN                                                       !0
   14    21*     > RETURN                                                       null

End of function flipa

Function fliparray:
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 = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 8
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 8
Branch analysis from position: 19
Branch analysis from position: 8
filename:       /in/ZL6eU
function name:  flipArray
number of ops:  23
compiled vars:  !0 = $arr, !1 = $arrayLength, !2 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
   25     1        COUNT                                                ~3      !0
          2        ASSIGN                                                       !1, ~3
   27     3        BOOL_NOT                                             ~5      !1
          4      > JMPZ                                                         ~5, ->6
   28     5    > > RETURN                                                       <array>
   31     6    >   ASSIGN                                                       !2, 0
          7      > JMP                                                          ->16
   32     8    >   INIT_FCALL_BY_NAME                                           'swapArrayElements'
          9        SEND_VAR_EX                                                  !0
         10        SEND_VAR_EX                                                  !2
         11        SUB                                                  ~7      !1, !2
         12        SUB                                                  ~8      ~7, 1
         13        SEND_VAL_EX                                                  ~8
         14        DO_FCALL                                          0          
   31    15        PRE_INC                                                      !2
         16    >   DIV                                                  ~11     !1, 2
         17        IS_SMALLER                                                   !2, ~11
         18      > JMPNZ                                                        ~12, ->8
   35    19    >   VERIFY_RETURN_TYPE                                           !0
         20      > RETURN                                                       !0
   36    21*       VERIFY_RETURN_TYPE                                           
         22*     > RETURN                                                       null

End of function fliparray

Function swaparrayelements:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZL6eU
function name:  swapArrayElements
number of ops:  11
compiled vars:  !0 = $arr, !1 = $i, !2 = $j, !3 = $tmp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   44     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   45     3        FETCH_DIM_R                                          ~4      !0, !1
          4        ASSIGN                                                       !3, ~4
   46     5        FETCH_DIM_R                                          ~7      !0, !2
          6        ASSIGN_DIM                                                   !0, !1
          7        OP_DATA                                                      ~7
   47     8        ASSIGN_DIM                                                   !0, !2
          9        OP_DATA                                                      !3
   48    10      > RETURN                                                       null

End of function swaparrayelements

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.83 ms | 1748 KiB | 16 Q