3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a1 = [121, 144, 19, 161, 19, 144, 19, 11]; $a2 = [11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]; var_dump(comp($a1, $a2) === TRUE); $a1 = [121, 144, 19, 161, 19, 144, 19, 11]; $a2 = [11*21, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]; $a1 = [121, 144, 19, 161, 19, 144, 19, 11]; $a2 = [11*11, 121*121, 144*144, 190*190, 161*161, 19*19, 144*144, 19*19]; $a1 = []; $a2 = []; $a1 = []; $a2 = null; $a1 = [121, 144, 19, 161, 19, 144, 19, 11, 1008]; $a2 = [11*11, 121*121, 144*144, 190*190, 161*161, 19*19, 144*144, 19*19]; $a1 = [10000000, 100000000]; $a2 = [10000000 * 10000000, 100000000 * 100000000]; $a1 = [10000001, 100000000]; $a2 = [10000000 * 10000000, 100000000 * 100000000]; $a1 = [2, 2, 3]; $a2 = [4, 9, 9]; function comp(array $array1 = NULL, array $array2 = NULL) : bool { $array1 = $array1 ?? []; $array2 = $array2 ?? []; $valid_comparison = $array1 !== NULL && $array2 !== NULL ? [[$array1, $array2]] : []; $valid_comparison = $array1 && $array2 ? [[$array1, $array2]] : []; $equal_squares = array_reduce($valid_comparison, 'compare_against_squares', false); return $equal_squares; } function compare_against_squares(bool $carry, array $arrays) : bool { list($array1, $array2) = $arrays; $array1_squared = array_map('square', $array1); return compare_sorted_arrays($array1_squared, $array2); } function compare_sorted_arrays(array $array1, array $array2) : bool { sort($array1); sort($array2); return $array1 == $array2; } function square(int $value) : float { return $value * $value; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OvJod
function name:  (null)
number of ops:  27
compiled vars:  !0 = $a1, !1 = $a2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL_BY_NAME                                       'comp'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $4      
          7        TYPE_CHECK                                    8  ~5      $4
          8        SEND_VAL                                                 ~5
          9        DO_ICALL                                                 
    7    10        ASSIGN                                                   !0, <array>
    8    11        ASSIGN                                                   !1, <array>
   10    12        ASSIGN                                                   !0, <array>
   11    13        ASSIGN                                                   !1, <array>
   13    14        ASSIGN                                                   !0, <array>
   14    15        ASSIGN                                                   !1, <array>
   16    16        ASSIGN                                                   !0, <array>
   17    17        ASSIGN                                                   !1, null
   19    18        ASSIGN                                                   !0, <array>
   20    19        ASSIGN                                                   !1, <array>
   22    20        ASSIGN                                                   !0, <array>
   23    21        ASSIGN                                                   !1, <array>
   25    22        ASSIGN                                                   !0, <array>
   26    23        ASSIGN                                                   !1, <array>
   28    24        ASSIGN                                                   !0, <array>
   29    25        ASSIGN                                                   !1, <array>
   56    26      > RETURN                                                   1

Function comp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
Branch analysis from position: 22
Branch analysis from position: 12
filename:       /in/OvJod
function name:  comp
number of ops:  40
compiled vars:  !0 = $array1, !1 = $array2, !2 = $valid_comparison, !3 = $equal_squares
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
   34     2        COALESCE                                         ~4      !0
          3        QM_ASSIGN                                        ~4      <array>
          4        ASSIGN                                                   !0, ~4
   35     5        COALESCE                                         ~6      !1
          6        QM_ASSIGN                                        ~6      <array>
          7        ASSIGN                                                   !1, ~6
   36     8        TYPE_CHECK                                  1020  ~8      !0
          9      > JMPZ_EX                                          ~8      ~8, ->12
         10    >   TYPE_CHECK                                  1020  ~9      !1
         11        BOOL                                             ~8      ~9
         12    > > JMPZ                                                     ~8, ->18
         13    >   INIT_ARRAY                                       ~10     !0
         14        ADD_ARRAY_ELEMENT                                ~10     !1
         15        INIT_ARRAY                                       ~11     ~10
         16        QM_ASSIGN                                        ~12     ~11
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~12     <array>
         19    >   ASSIGN                                                   !2, ~12
   37    20      > JMPZ_EX                                          ~14     !0, ->22
         21    >   BOOL                                             ~14     !1
         22    > > JMPZ                                                     ~14, ->28
         23    >   INIT_ARRAY                                       ~15     !0
         24        ADD_ARRAY_ELEMENT                                ~15     !1
         25        INIT_ARRAY                                       ~16     ~15
         26        QM_ASSIGN                                        ~17     ~16
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~17     <array>
         29    >   ASSIGN                                                   !2, ~17
   38    30        INIT_FCALL                                               'array_reduce'
         31        SEND_VAR                                                 !2
         32        SEND_VAL                                                 'compare_against_squares'
         33        SEND_VAL                                                 <false>
         34        DO_ICALL                                         $19     
         35        ASSIGN                                                   !3, $19
   39    36        VERIFY_RETURN_TYPE                                       !3
         37      > RETURN                                                   !3
   40    38*       VERIFY_RETURN_TYPE                                       
         39*     > RETURN                                                   null

End of function comp

Function compare_against_squares:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OvJod
function name:  compare_against_squares
number of ops:  21
compiled vars:  !0 = $carry, !1 = $arrays, !2 = $array1, !3 = $array2, !4 = $array1_squared
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   43     2        QM_ASSIGN                                        ~5      !1
          3        FETCH_LIST_R                                     $6      ~5, 0
          4        ASSIGN                                                   !2, $6
          5        FETCH_LIST_R                                     $8      ~5, 1
          6        ASSIGN                                                   !3, $8
          7        FREE                                                     ~5
   44     8        INIT_FCALL                                               'array_map'
          9        SEND_VAL                                                 'square'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !4, $10
   45    13        INIT_FCALL_BY_NAME                                       'compare_sorted_arrays'
         14        SEND_VAR_EX                                              !4
         15        SEND_VAR_EX                                              !3
         16        DO_FCALL                                      0  $12     
         17        VERIFY_RETURN_TYPE                                       $12
         18      > RETURN                                                   $12
   46    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function compare_against_squares

Function compare_sorted_arrays:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OvJod
function name:  compare_sorted_arrays
number of ops:  13
compiled vars:  !0 = $array1, !1 = $array2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   49     2        INIT_FCALL                                               'sort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
   50     5        INIT_FCALL                                               'sort'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                                 
   51     8        IS_EQUAL                                         ~4      !0, !1
          9        VERIFY_RETURN_TYPE                                       ~4
         10      > RETURN                                                   ~4
   52    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function compare_sorted_arrays

Function square:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OvJod
function name:  square
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   55     1        MUL                                              ~1      !0, !0
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   56     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function square

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.42 ms | 1404 KiB | 21 Q