3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * convert square definition from x,y,l (x,y, length) to x1,y1,x2,y2 */ function point($sq) { return array( 'x1' => $sq['x'], 'y1' => $sq['y'], 'x2' => $sq['x'] + $sq['l'], 'y2' => $sq['y'] + $sq['l'], ); } /* * return intersect square */ function intersect(array $ps) { $r = max(array_map(function($e) { return $e['x1']; }, $ps)); $l = min(array_map(function($e) { return $e['x2']; }, $ps)); $t = max(array_map(function($e) { return $e['y1']; }, $ps)); $b = min(array_map(function($e) { return $e['y2']; }, $ps)); if ($r < $l && $b > $t) { return array( 'x1' => $l, 'y1' => $b, 'x2' => $r, 'y2' => $t, ); } return false; } /* * return square area */ function area($sq) { return abs(($sq['x1'] - $sq['x2']) * ($sq['y1'] - $sq['y2'])); } // input data $sq1 = array('x' => 2, 'y' => 2, 'l' => 4); $sq2 = array('x' => 3, 'y' => 2, 'l' => 4); echo 'Intersect: ' . ((false !== $intersect = intersect(array(point($sq1), point($sq2)))) ? 'yes' : 'no') . PHP_EOL; if (false !== $intersect) { echo 'Area: ' . area($intersect) . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
Branch analysis from position: 30
filename:       /in/T3I63
function name:  (null)
number of ops:  31
compiled vars:  !0 = $sq1, !1 = $sq2, !2 = $intersect
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   ASSIGN                                                   !0, <array>
   48     1        ASSIGN                                                   !1, <array>
   50     2        INIT_FCALL                                               'intersect'
          3        INIT_FCALL                                               'point'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $5      
          6        INIT_ARRAY                                       ~6      $5
          7        INIT_FCALL                                               'point'
          8        SEND_VAR                                                 !1
          9        DO_FCALL                                      0  $7      
         10        ADD_ARRAY_ELEMENT                                ~6      $7
         11        SEND_VAL                                                 ~6
         12        DO_FCALL                                      0  $8      
         13        ASSIGN                                           ~9      !2, $8
         14        TYPE_CHECK                                  1018          ~9
         15      > JMPZ                                                     ~10, ->18
         16    >   QM_ASSIGN                                        ~11     'yes'
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~11     'no'
         19    >   CONCAT                                           ~12     'Intersect%3A+', ~11
         20        CONCAT                                           ~13     ~12, '%0A'
         21        ECHO                                                     ~13
   51    22        TYPE_CHECK                                  1018          !2
         23      > JMPZ                                                     ~14, ->30
   52    24    >   INIT_FCALL                                               'area'
         25        SEND_VAR                                                 !2
         26        DO_FCALL                                      0  $15     
         27        CONCAT                                           ~16     'Area%3A+', $15
         28        CONCAT                                           ~17     ~16, '%0A'
         29        ECHO                                                     ~17
   53    30    > > RETURN                                                   1

Function point:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/T3I63
function name:  point
number of ops:  15
compiled vars:  !0 = $sq
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    9     1        FETCH_DIM_R                                      ~1      !0, 'x'
          2        INIT_ARRAY                                       ~2      ~1, 'x1'
   10     3        FETCH_DIM_R                                      ~3      !0, 'y'
          4        ADD_ARRAY_ELEMENT                                ~2      ~3, 'y1'
   11     5        FETCH_DIM_R                                      ~4      !0, 'x'
          6        FETCH_DIM_R                                      ~5      !0, 'l'
          7        ADD                                              ~6      ~4, ~5
          8        ADD_ARRAY_ELEMENT                                ~2      ~6, 'x2'
   12     9        FETCH_DIM_R                                      ~7      !0, 'y'
         10        FETCH_DIM_R                                      ~8      !0, 'l'
         11        ADD                                              ~9      ~7, ~8
         12        ADD_ARRAY_ELEMENT                                ~2      ~9, 'y2'
         13      > RETURN                                                   ~2
   14    14*     > RETURN                                                   null

End of function point

Function intersect:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 47
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/T3I63
function name:  intersect
number of ops:  49
compiled vars:  !0 = $ps, !1 = $r, !2 = $l, !3 = $t, !4 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'max'
          2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FT3I63%3A21%240'
          4        SEND_VAL                                                 ~5
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $6      
          7        SEND_VAR                                                 $6
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !1, $7
   22    10        INIT_FCALL                                               'min'
         11        INIT_FCALL                                               'array_map'
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FT3I63%3A22%241'
         13        SEND_VAL                                                 ~9
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $10     
         16        SEND_VAR                                                 $10
         17        DO_ICALL                                         $11     
         18        ASSIGN                                                   !2, $11
   24    19        INIT_FCALL                                               'max'
         20        INIT_FCALL                                               'array_map'
         21        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FT3I63%3A24%242'
         22        SEND_VAL                                                 ~13
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $14     
         25        SEND_VAR                                                 $14
         26        DO_ICALL                                         $15     
         27        ASSIGN                                                   !3, $15
   25    28        INIT_FCALL                                               'min'
         29        INIT_FCALL                                               'array_map'
         30        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FT3I63%3A25%243'
         31        SEND_VAL                                                 ~17
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $18     
         34        SEND_VAR                                                 $18
         35        DO_ICALL                                         $19     
         36        ASSIGN                                                   !4, $19
   28    37        IS_SMALLER                                       ~21     !1, !2
         38      > JMPZ_EX                                          ~21     ~21, ->41
         39    >   IS_SMALLER                                       ~22     !3, !4
         40        BOOL                                             ~21     ~22
         41    > > JMPZ                                                     ~21, ->47
   30    42    >   INIT_ARRAY                                       ~23     !2, 'x1'
   31    43        ADD_ARRAY_ELEMENT                                ~23     !4, 'y1'
   32    44        ADD_ARRAY_ELEMENT                                ~23     !1, 'x2'
   33    45        ADD_ARRAY_ELEMENT                                ~23     !3, 'y2'
         46      > RETURN                                                   ~23
   36    47    > > RETURN                                                   <false>
   37    48*     > RETURN                                                   null

End of function intersect

Function %00%7Bclosure%7D%2Fin%2FT3I63%3A21%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/T3I63
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'x1'
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FT3I63%3A21%240

Function %00%7Bclosure%7D%2Fin%2FT3I63%3A22%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/T3I63
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'x2'
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FT3I63%3A22%241

Function %00%7Bclosure%7D%2Fin%2FT3I63%3A24%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/T3I63
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'y1'
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FT3I63%3A24%242

Function %00%7Bclosure%7D%2Fin%2FT3I63%3A25%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/T3I63
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'y2'
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FT3I63%3A25%243

Function area:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/T3I63
function name:  area
number of ops:  13
compiled vars:  !0 = $sq
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'abs'
          2        FETCH_DIM_R                                      ~1      !0, 'x1'
          3        FETCH_DIM_R                                      ~2      !0, 'x2'
          4        SUB                                              ~3      ~1, ~2
          5        FETCH_DIM_R                                      ~4      !0, 'y1'
          6        FETCH_DIM_R                                      ~5      !0, 'y2'
          7        SUB                                              ~6      ~4, ~5
          8        MUL                                              ~7      ~3, ~6
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                         $8      
         11      > RETURN                                                   $8
   44    12*     > RETURN                                                   null

End of function area

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.19 ms | 1411 KiB | 25 Q