3v4l.org

run code in 500+ PHP versions simultaneously
<?php $canonicalIds = [ 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', ]; $putContent = [ [ 'id' => 'fifth', 'value' => 55, ], [ 'id' => 'second', 'value' => 22, ], [ 'id' => 'fourth', 'value' => 44, ], [ 'id' => null, 'value' => 7, ], ]; [$toCreate, $toUpdate] = array_reduce( $putContent, static function (array $carry, array $item) use ($canonicalIds): array { [$toCreate, $toUpdate] = $carry; if (null === $item['id']) { $toCreate[] = $item; } elseif (true === in_array($item['id'], $canonicalIds, true)) { $toUpdate[$item['id']] = $item; } return [ $toCreate, $toUpdate ]; }, [ [], [] ] ); $toDelete = array_diff($canonicalIds, array_keys($toUpdate)); var_dump($toCreate, $toUpdate, $toDelete);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A0vNU
function name:  (null)
number of ops:  28
compiled vars:  !0 = $canonicalIds, !1 = $putContent, !2 = $toCreate, !3 = $toUpdate, !4 = $toDelete
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   12     1        ASSIGN                                                       !1, <array>
   31     2        INIT_FCALL                                                   'array_reduce'
   32     3        SEND_VAR                                                     !1
   33     4        DECLARE_LAMBDA_FUNCTION                              ~7      [0]
          5        BIND_LEXICAL                                                 ~7, !0
   46     6        SEND_VAL                                                     ~7
   48     7        SEND_VAL                                                     <array>
   31     8        DO_ICALL                                             $8      
   48     9        FETCH_LIST_R                                         $9      $8, 0
   31    10        ASSIGN                                                       !2, $9
         11        FETCH_LIST_R                                         $11     $8, 1
         12        ASSIGN                                                       !3, $11
         13        FREE                                                         $8
   53    14        INIT_FCALL                                                   'array_diff'
         15        SEND_VAR                                                     !0
         16        INIT_FCALL                                                   'array_keys'
         17        SEND_VAR                                                     !3
         18        DO_ICALL                                             $13     
         19        SEND_VAR                                                     $13
         20        DO_ICALL                                             $14     
         21        ASSIGN                                                       !4, $14
   55    22        INIT_FCALL                                                   'var_dump'
         23        SEND_VAR                                                     !2
         24        SEND_VAR                                                     !3
         25        SEND_VAR                                                     !4
         26        DO_ICALL                                                     
         27      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/A0vNU
function name:  {closure:/in/A0vNU:33}
number of ops:  29
compiled vars:  !0 = $carry, !1 = $item, !2 = $canonicalIds, !3 = $toCreate, !4 = $toUpdate
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   33     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   34     3        QM_ASSIGN                                            ~5      !0
          4        FETCH_LIST_R                                         $6      ~5, 0
          5        ASSIGN                                                       !3, $6
          6        FETCH_LIST_R                                         $8      ~5, 1
          7        ASSIGN                                                       !4, $8
          8        FREE                                                         ~5
   36     9        FETCH_DIM_R                                          ~10     !1, 'id'
         10        TYPE_CHECK                                        2          ~10
         11      > JMPZ                                                         ~11, ->15
   37    12    >   ASSIGN_DIM                                                   !3
         13        OP_DATA                                                      !1
   36    14      > JMP                                                          ->23
   38    15    >   FETCH_DIM_R                                          ~13     !1, 'id'
         16        FRAMELESS_ICALL_3                in_array            ~14     ~13, !2
         17        OP_DATA                                                      <true>
         18        TYPE_CHECK                                        8          ~14
         19      > JMPZ                                                         ~15, ->23
   39    20    >   FETCH_DIM_R                                          ~16     !1, 'id'
         21        ASSIGN_DIM                                                   !4, ~16
         22        OP_DATA                                                      !1
   43    23    >   INIT_ARRAY                                           ~18     !3
   44    24        ADD_ARRAY_ELEMENT                                    ~18     !4
         25        VERIFY_RETURN_TYPE                                           ~18
         26      > RETURN                                                       ~18
   46    27*       VERIFY_RETURN_TYPE                                           
         28*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
213.65 ms | 1832 KiB | 17 Q