3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mergeAttachments($a, $b) { // If both #attached arrays contain drupalSettings, then merge them // correctly; adding the same settings multiple times needs to behave // idempotently. if (!empty($b['drupalSettings'])) { $temp = mergeDeepArray([$a['drupalSettings'], $b['drupalSettings']], TRUE); } $a = mergeDeepArray([$a, $b]); if (isset($temp)) { $a['drupalSettings'] = $temp; } return $a; } function mergeAttachmentsOld($a, $b) { if (!empty($a['drupalSettings']) && !empty($b['drupalSettings'])) { $a['drupalSettings'] = mergeDeepArray([$a['drupalSettings'], $b['drupalSettings']], TRUE); unset($b['drupalSettings']); } return mergeDeep($a, $b); } function mergeDeepArray($arrays, $preserve_integer_keys = FALSE) { $result = array(); foreach ($arrays as $array) { foreach ($array as $key => $value) { // Renumber integer keys as array_merge_recursive() does unless // $preserve_integer_keys is set to TRUE. Note that PHP automatically // converts array keys that are integer strings (e.g., '1') to integers. if (is_integer($key) && !$preserve_integer_keys) { $result[] = $value; } // Recurse when both values are arrays. elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) { $result[$key] = mergeDeepArray(array($result[$key], $value), $preserve_integer_keys); } // Otherwise, use the latter value, overriding any previous value. else { $result[$key] = $value; } } } return $result; } function mergeDeep() { return mergeDeepArray(func_get_args()); } for($i = 0; $i <= 10000; $i++) { $a['#attached'] = array( 'library' => array( 'core/drupal', 'core/drupalSettings', ), ); $b['#attached'] = array( 'library' => array( 'core/jquery', ), ); mergeAttachmentsOld($a['#attached'], $b['#attached']); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 2
Branch analysis from position: 15
Branch analysis from position: 2
filename:       /in/Kpf1o
function name:  (null)
number of ops:  16
compiled vars:  !0 = $i, !1 = $a, !2 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->13
   53     2    >   ASSIGN_DIM                                               !1, '%23attached'
   55     3        OP_DATA                                                  <array>
   59     4        ASSIGN_DIM                                               !2, '%23attached'
   61     5        OP_DATA                                                  <array>
   64     6        INIT_FCALL                                               'mergeattachmentsold'
          7        FETCH_DIM_R                                      ~6      !1, '%23attached'
          8        SEND_VAL                                                 ~6
          9        FETCH_DIM_R                                      ~7      !2, '%23attached'
         10        SEND_VAL                                                 ~7
         11        DO_FCALL                                      0          
   52    12        PRE_INC                                                  !0
         13    >   IS_SMALLER_OR_EQUAL                                      !0, 10000
         14      > JMPNZ                                                    ~10, ->2
   65    15    > > RETURN                                                   1

Function mergeattachments:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 14
filename:       /in/Kpf1o
function name:  mergeAttachments
number of ops:  26
compiled vars:  !0 = $a, !1 = $b, !2 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        ISSET_ISEMPTY_DIM_OBJ                         1  ~3      !1, 'drupalSettings'
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->14
    8     5    >   INIT_FCALL_BY_NAME                                       'mergeDeepArray'
          6        FETCH_DIM_R                                      ~5      !0, 'drupalSettings'
          7        INIT_ARRAY                                       ~6      ~5
          8        FETCH_DIM_R                                      ~7      !1, 'drupalSettings'
          9        ADD_ARRAY_ELEMENT                                ~6      ~7
         10        SEND_VAL_EX                                              ~6
         11        SEND_VAL_EX                                              <true>
         12        DO_FCALL                                      0  $8      
         13        ASSIGN                                                   !2, $8
   10    14    >   INIT_FCALL_BY_NAME                                       'mergeDeepArray'
         15        INIT_ARRAY                                       ~10     !0
         16        ADD_ARRAY_ELEMENT                                ~10     !1
         17        SEND_VAL_EX                                              ~10
         18        DO_FCALL                                      0  $11     
         19        ASSIGN                                                   !0, $11
   11    20        ISSET_ISEMPTY_CV                                         !2
         21      > JMPZ                                                     ~13, ->24
   12    22    >   ASSIGN_DIM                                               !0, 'drupalSettings'
         23        OP_DATA                                                  !2
   14    24    > > RETURN                                                   !0
   15    25*     > RETURN                                                   null

End of function mergeattachments

Function mergeattachmentsold:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 8
filename:       /in/Kpf1o
function name:  mergeAttachmentsOld
number of ops:  26
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        ISSET_ISEMPTY_DIM_OBJ                         1  ~2      !0, 'drupalSettings'
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ_EX                                          ~3      ~3, ->8
          5    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~4      !1, 'drupalSettings'
          6        BOOL_NOT                                         ~5      ~4
          7        BOOL                                             ~3      ~5
          8    > > JMPZ                                                     ~3, ->20
   19     9    >   INIT_FCALL_BY_NAME                                       'mergeDeepArray'
         10        FETCH_DIM_R                                      ~7      !0, 'drupalSettings'
         11        INIT_ARRAY                                       ~8      ~7
         12        FETCH_DIM_R                                      ~9      !1, 'drupalSettings'
         13        ADD_ARRAY_ELEMENT                                ~8      ~9
         14        SEND_VAL_EX                                              ~8
         15        SEND_VAL_EX                                              <true>
         16        DO_FCALL                                      0  $10     
         17        ASSIGN_DIM                                               !0, 'drupalSettings'
         18        OP_DATA                                                  $10
   20    19        UNSET_DIM                                                !1, 'drupalSettings'
   22    20    >   INIT_FCALL_BY_NAME                                       'mergeDeep'
         21        SEND_VAR_EX                                              !0
         22        SEND_VAR_EX                                              !1
         23        DO_FCALL                                      0  $11     
         24      > RETURN                                                   $11
   23    25*     > RETURN                                                   null

End of function mergeattachmentsold

Function mergedeeparray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 40
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 40
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 38
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 38
Branch analysis from position: 7
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 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 24
Branch analysis from position: 21
Branch analysis from position: 12
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 38
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/Kpf1o
function name:  mergeDeepArray
number of ops:  43
compiled vars:  !0 = $arrays, !1 = $preserve_integer_keys, !2 = $result, !3 = $array, !4 = $value, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   26     2        ASSIGN                                                   !2, <array>
   27     3      > FE_RESET_R                                       $7      !0, ->40
          4    > > FE_FETCH_R                                               $7, !3, ->40
   28     5    > > FE_RESET_R                                       $8      !3, ->38
          6    > > FE_FETCH_R                                       ~9      $8, !4, ->38
          7    >   ASSIGN                                                   !5, ~9
   32     8        TYPE_CHECK                                   16  ~11     !5
          9      > JMPZ_EX                                          ~11     ~11, ->12
         10    >   BOOL_NOT                                         ~12     !1
         11        BOOL                                             ~11     ~12
         12    > > JMPZ                                                     ~11, ->16
   33    13    >   ASSIGN_DIM                                               !2
         14        OP_DATA                                                  !4
         15      > JMP                                                      ->37
   36    16    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~14     !2, !5
         17      > JMPZ_EX                                          ~14     ~14, ->21
         18    >   FETCH_DIM_R                                      ~15     !2, !5
         19        TYPE_CHECK                                  128  ~16     ~15
         20        BOOL                                             ~14     ~16
         21    > > JMPZ_EX                                          ~14     ~14, ->24
         22    >   TYPE_CHECK                                  128  ~17     !4
         23        BOOL                                             ~14     ~17
         24    > > JMPZ                                                     ~14, ->35
   37    25    >   INIT_FCALL_BY_NAME                                       'mergeDeepArray'
         26        FETCH_DIM_R                                      ~19     !2, !5
         27        INIT_ARRAY                                       ~20     ~19
         28        ADD_ARRAY_ELEMENT                                ~20     !4
         29        SEND_VAL_EX                                              ~20
         30        SEND_VAR_EX                                              !1
         31        DO_FCALL                                      0  $21     
         32        ASSIGN_DIM                                               !2, !5
         33        OP_DATA                                                  $21
         34      > JMP                                                      ->37
   41    35    >   ASSIGN_DIM                                               !2, !5
         36        OP_DATA                                                  !4
   28    37    > > JMP                                                      ->6
         38    >   FE_FREE                                                  $8
   27    39      > JMP                                                      ->4
         40    >   FE_FREE                                                  $7
   45    41      > RETURN                                                   !2
   46    42*     > RETURN                                                   null

End of function mergedeeparray

Function mergedeep:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kpf1o
function name:  mergeDeep
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   INIT_FCALL                                               'mergedeeparray'
          1        FUNC_GET_ARGS                                    ~0      
          2        SEND_VAL                                                 ~0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   50     5*     > RETURN                                                   null

End of function mergedeep

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.13 ms | 1402 KiB | 15 Q