3v4l.org

run code in 500+ PHP versions simultaneously
<?php $before = [ 'name' => 'Bertie', 'age' => '23' ]; $after = [ 'name' => 'Harold', 'age' => '23', 'occupation' => 'Bus driver' ]; function changed_1($after, $before) { return array_diff_assoc($after, $before); } function changed_2($after, $before) { $changed = []; foreach($after as $k => $v) { if(isset($before[$k]) && $before[$k] !== $v) $changed[$k] = $v; if(!isset($before[$k])) $changed[$k] = $v; } return $changed; } var_export(changed_1($after, $before)); var_export(changed_2($after, $before)); /* Output: array ( 'name' => 'Harold', 'occupation' => 'Bus driver', )array ( 'name' => 'Harold', 'occupation' => 'Bus driver', ) */ // 26 * 26 * 6 = 4056, aA1 aA2 aB1 foreach(range('a', 'z') as $char1) foreach(range('A', 'Z') as $char2) foreach(range('1', '5') as $char3) { $key = $char1 . $char2 . $char3; $data1[$key] = $char1 . $char2 . $char3; $data2[$key] = $char1 . $char3 . $char2; } prof_flag('changed_1'); changed_1($data2, $data1); prof_flag('changed_2'); changed_2($data2, $data1); prof_flag("Done"); prof_print(); // SO TimH https://stackoverflow.com/a/29022400/3392762 function prof_flag($str) { global $prof_timing, $prof_names; $prof_timing[] = microtime(true); $prof_names[] = $str; } // Call this when you're done and want to see the results function prof_print() { global $prof_timing, $prof_names; $size = count($prof_timing); for($i=0;$i<$size - 1; $i++) { echo "<b>{$prof_names[$i]}</b><br>"; echo sprintf("&nbsp;&nbsp;&nbsp;%f<br>", $prof_timing[$i+1]-$prof_timing[$i]); } echo "<b>{$prof_names[$size-1]}</b><br>"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 50
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 50
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 48
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 48
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 46
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 46
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 46
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 48
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
filename:       /in/pS8uc
function name:  (null)
number of ops:  71
compiled vars:  !0 = $before, !1 = $after, !2 = $char1, !3 = $char2, !4 = $char3, !5 = $key, !6 = $data1, !7 = $data2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    7     1        ASSIGN                                                       !1, <array>
   29     2        INIT_FCALL                                                   'var_export'
          3        INIT_FCALL                                                   'changed_1'
          4        SEND_VAR                                                     !1
          5        SEND_VAR                                                     !0
          6        DO_FCALL                                          0  $10     
          7        SEND_VAR                                                     $10
          8        DO_ICALL                                                     
   30     9        INIT_FCALL                                                   'var_export'
         10        INIT_FCALL                                                   'changed_2'
         11        SEND_VAR                                                     !1
         12        SEND_VAR                                                     !0
         13        DO_FCALL                                          0  $12     
         14        SEND_VAR                                                     $12
         15        DO_ICALL                                                     
   45    16        INIT_FCALL                                                   'range'
         17        SEND_VAL                                                     'a'
         18        SEND_VAL                                                     'z'
         19        DO_ICALL                                             $14     
         20      > FE_RESET_R                                           $15     $14, ->50
         21    > > FE_FETCH_R                                                   $15, !2, ->50
   46    22    >   INIT_FCALL                                                   'range'
         23        SEND_VAL                                                     'A'
         24        SEND_VAL                                                     'Z'
         25        DO_ICALL                                             $16     
         26      > FE_RESET_R                                           $17     $16, ->48
         27    > > FE_FETCH_R                                                   $17, !3, ->48
   47    28    >   INIT_FCALL                                                   'range'
         29        SEND_VAL                                                     '1'
         30        SEND_VAL                                                     '5'
         31        DO_ICALL                                             $18     
         32      > FE_RESET_R                                           $19     $18, ->46
         33    > > FE_FETCH_R                                                   $19, !4, ->46
   48    34    >   CONCAT                                               ~20     !2, !3
         35        CONCAT                                               ~21     ~20, !4
         36        ASSIGN                                                       !5, ~21
   49    37        CONCAT                                               ~24     !2, !3
         38        CONCAT                                               ~25     ~24, !4
         39        ASSIGN_DIM                                                   !6, !5
         40        OP_DATA                                                      ~25
   50    41        CONCAT                                               ~27     !2, !4
         42        CONCAT                                               ~28     ~27, !3
         43        ASSIGN_DIM                                                   !7, !5
         44        OP_DATA                                                      ~28
   47    45      > JMP                                                          ->33
         46    >   FE_FREE                                                      $19
   46    47      > JMP                                                          ->27
         48    >   FE_FREE                                                      $17
   45    49      > JMP                                                          ->21
         50    >   FE_FREE                                                      $15
   53    51        INIT_FCALL_BY_NAME                                           'prof_flag'
         52        SEND_VAL_EX                                                  'changed_1'
         53        DO_FCALL                                          0          
   54    54        INIT_FCALL                                                   'changed_1'
         55        SEND_VAR                                                     !7
         56        SEND_VAR                                                     !6
         57        DO_FCALL                                          0          
   55    58        INIT_FCALL_BY_NAME                                           'prof_flag'
         59        SEND_VAL_EX                                                  'changed_2'
         60        DO_FCALL                                          0          
   56    61        INIT_FCALL                                                   'changed_2'
         62        SEND_VAR                                                     !7
         63        SEND_VAR                                                     !6
         64        DO_FCALL                                          0          
   57    65        INIT_FCALL_BY_NAME                                           'prof_flag'
         66        SEND_VAL_EX                                                  'Done'
         67        DO_FCALL                                          0          
   58    68        INIT_FCALL_BY_NAME                                           'prof_print'
         69        DO_FCALL                                          0          
   79    70      > RETURN                                                       1

Function changed_1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pS8uc
function name:  changed_1
number of ops:  8
compiled vars:  !0 = $after, !1 = $before
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   14     2        INIT_FCALL                                                   'array_diff_assoc'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_ICALL                                             $2      
          6      > RETURN                                                       $2
   15     7*     > RETURN                                                       null

End of function changed_1

Function changed_2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
Branch analysis from position: 14
Branch analysis from position: 11
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/pS8uc
function name:  changed_2
number of ops:  23
compiled vars:  !0 = $after, !1 = $before, !2 = $changed, !3 = $v, !4 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   18     2        ASSIGN                                                       !2, <array>
   19     3      > FE_RESET_R                                           $6      !0, ->20
          4    > > FE_FETCH_R                                           ~7      $6, !3, ->20
          5    >   ASSIGN                                                       !4, ~7
   20     6        ISSET_ISEMPTY_DIM_OBJ                             0  ~9      !1, !4
          7      > JMPZ_EX                                              ~9      ~9, ->11
          8    >   FETCH_DIM_R                                          ~10     !1, !4
          9        IS_NOT_IDENTICAL                                     ~11     !3, ~10
         10        BOOL                                                 ~9      ~11
         11    > > JMPZ                                                         ~9, ->14
   21    12    >   ASSIGN_DIM                                                   !2, !4
         13        OP_DATA                                                      !3
   22    14    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~13     !1, !4
         15        BOOL_NOT                                             ~14     ~13
         16      > JMPZ                                                         ~14, ->19
   23    17    >   ASSIGN_DIM                                                   !2, !4
         18        OP_DATA                                                      !3
   19    19    > > JMP                                                          ->4
         20    >   FE_FREE                                                      $6
   26    21      > RETURN                                                       !2
   27    22*     > RETURN                                                       null

End of function changed_2

Function prof_flag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pS8uc
function name:  prof_flag
number of ops:  11
compiled vars:  !0 = $str, !1 = $prof_timing, !2 = $prof_names
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   61     0  E >   RECV                                                 !0      
   63     1        BIND_GLOBAL                                                  !1, 'prof_timing'
          2        BIND_GLOBAL                                                  !2, 'prof_names'
   64     3        INIT_FCALL                                                   'microtime'
          4        SEND_VAL                                                     <true>
          5        DO_ICALL                                             $4      
          6        ASSIGN_DIM                                                   !1
          7        OP_DATA                                                      $4
   65     8        ASSIGN_DIM                                                   !2
          9        OP_DATA                                                      !0
   66    10      > RETURN                                                       null

End of function prof_flag

Function prof_print:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 6
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 6
Branch analysis from position: 24
Branch analysis from position: 6
filename:       /in/pS8uc
function name:  prof_print
number of ops:  31
compiled vars:  !0 = $prof_timing, !1 = $prof_names, !2 = $size, !3 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   71     0  E >   BIND_GLOBAL                                                  !0, 'prof_timing'
          1        BIND_GLOBAL                                                  !1, 'prof_names'
   72     2        COUNT                                                ~4      !0
          3        ASSIGN                                                       !2, ~4
   73     4        ASSIGN                                                       !3, 0
          5      > JMP                                                          ->21
   75     6    >   ROPE_INIT                                         3  ~9      '%3Cb%3E'
          7        FETCH_DIM_R                                          ~7      !1, !3
          8        ROPE_ADD                                          1  ~9      ~9, ~7
          9        ROPE_END                                          2  ~8      ~9, '%3C%2Fb%3E%3Cbr%3E'
         10        ECHO                                                         ~8
   76    11        INIT_FCALL                                                   'sprintf'
         12        SEND_VAL                                                     '%26nbsp%3B%26nbsp%3B%26nbsp%3B%25f%3Cbr%3E'
         13        ADD                                                  ~11     !3, 1
         14        FETCH_DIM_R                                          ~12     !0, ~11
         15        FETCH_DIM_R                                          ~13     !0, !3
         16        SUB                                                  ~14     ~12, ~13
         17        SEND_VAL                                                     ~14
         18        DO_ICALL                                             $15     
         19        ECHO                                                         $15
   73    20        PRE_INC                                                      !3
         21    >   SUB                                                  ~17     !2, 1
         22        IS_SMALLER                                                   !3, ~17
         23      > JMPNZ                                                        ~18, ->6
   78    24    >   ROPE_INIT                                         3  ~22     '%3Cb%3E'
         25        SUB                                                  ~19     !2, 1
         26        FETCH_DIM_R                                          ~20     !1, ~19
         27        ROPE_ADD                                          1  ~22     ~22, ~20
         28        ROPE_END                                          2  ~21     ~22, '%3C%2Fb%3E%3Cbr%3E'
         29        ECHO                                                         ~21
   79    30      > RETURN                                                       null

End of function prof_print

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.88 ms | 2416 KiB | 22 Q