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]; var_dump(comp($a1, $a2) === FALSE); $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]; var_dump(comp($a1, $a2) === FALSE); $a1 = []; $a2 = []; var_dump(comp($a1, $a2) === TRUE); $a1 = []; $a2 = null; var_dump(comp($a1, $a2) === FALSE); $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 && $array2 ? [[$array1, $array2]] : []; $equal_squares = array_reduce($valid_comparison, 'compare_against_squares', $array1 == $array2); 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/QZ4OO
function name:  (null)
number of ops:  59
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>
    9    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL_BY_NAME                                       'comp'
         14        SEND_VAR_EX                                              !0
         15        SEND_VAR_EX                                              !1
         16        DO_FCALL                                      0  $9      
         17        TYPE_CHECK                                    4  ~10     $9
         18        SEND_VAL                                                 ~10
         19        DO_ICALL                                                 
   10    20        ASSIGN                                                   !0, <array>
   11    21        ASSIGN                                                   !1, <array>
   12    22        INIT_FCALL                                               'var_dump'
         23        INIT_FCALL_BY_NAME                                       'comp'
         24        SEND_VAR_EX                                              !0
         25        SEND_VAR_EX                                              !1
         26        DO_FCALL                                      0  $14     
         27        TYPE_CHECK                                    4  ~15     $14
         28        SEND_VAL                                                 ~15
         29        DO_ICALL                                                 
   13    30        ASSIGN                                                   !0, <array>
   14    31        ASSIGN                                                   !1, <array>
   15    32        INIT_FCALL                                               'var_dump'
         33        INIT_FCALL_BY_NAME                                       'comp'
         34        SEND_VAR_EX                                              !0
         35        SEND_VAR_EX                                              !1
         36        DO_FCALL                                      0  $19     
         37        TYPE_CHECK                                    8  ~20     $19
         38        SEND_VAL                                                 ~20
         39        DO_ICALL                                                 
   16    40        ASSIGN                                                   !0, <array>
   17    41        ASSIGN                                                   !1, null
   18    42        INIT_FCALL                                               'var_dump'
         43        INIT_FCALL_BY_NAME                                       'comp'
         44        SEND_VAR_EX                                              !0
         45        SEND_VAR_EX                                              !1
         46        DO_FCALL                                      0  $24     
         47        TYPE_CHECK                                    4  ~25     $24
         48        SEND_VAL                                                 ~25
         49        DO_ICALL                                                 
   19    50        ASSIGN                                                   !0, <array>
   20    51        ASSIGN                                                   !1, <array>
   22    52        ASSIGN                                                   !0, <array>
   23    53        ASSIGN                                                   !1, <array>
   25    54        ASSIGN                                                   !0, <array>
   26    55        ASSIGN                                                   !1, <array>
   28    56        ASSIGN                                                   !0, <array>
   29    57        ASSIGN                                                   !1, <array>
   55    58      > RETURN                                                   1

Function comp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/QZ4OO
function name:  comp
number of ops:  29
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      > JMPZ_EX                                          ~8      !0, ->10
          9    >   BOOL                                             ~8      !1
         10    > > JMPZ                                                     ~8, ->16
         11    >   INIT_ARRAY                                       ~9      !0
         12        ADD_ARRAY_ELEMENT                                ~9      !1
         13        INIT_ARRAY                                       ~10     ~9
         14        QM_ASSIGN                                        ~11     ~10
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~11     <array>
         17    >   ASSIGN                                                   !2, ~11
   37    18        INIT_FCALL                                               'array_reduce'
         19        SEND_VAR                                                 !2
         20        SEND_VAL                                                 'compare_against_squares'
         21        IS_EQUAL                                         ~13     !0, !1
         22        SEND_VAL                                                 ~13
         23        DO_ICALL                                         $14     
         24        ASSIGN                                                   !3, $14
   38    25        VERIFY_RETURN_TYPE                                       !3
         26      > RETURN                                                   !3
   39    27*       VERIFY_RETURN_TYPE                                       
         28*     > 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/QZ4OO
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
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   42     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
   43     8        INIT_FCALL                                               'array_map'
          9        SEND_VAL                                                 'square'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !4, $10
   44    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
   45    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/QZ4OO
function name:  compare_sorted_arrays
number of ops:  13
compiled vars:  !0 = $array1, !1 = $array2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   48     2        INIT_FCALL                                               'sort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
   49     5        INIT_FCALL                                               'sort'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                                 
   50     8        IS_EQUAL                                         ~4      !0, !1
          9        VERIFY_RETURN_TYPE                                       ~4
         10      > RETURN                                                   ~4
   51    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/QZ4OO
function name:  square
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1        MUL                                              ~1      !0, !0
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   55     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function square

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.22 ms | 1408 KiB | 21 Q