3v4l.org

run code in 300+ 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 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/A0vNU
function name:  {closure}
number of ops:  32
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                                                      ->26
   38    15    >   INIT_FCALL                                               'in_array'
         16        FETCH_DIM_R                                      ~13     !1, 'id'
         17        SEND_VAL                                                 ~13
         18        SEND_VAR                                                 !2
         19        SEND_VAL                                                 <true>
         20        DO_ICALL                                         $14     
         21        TYPE_CHECK                                    8          $14
         22      > JMPZ                                                     ~15, ->26
   39    23    >   FETCH_DIM_R                                      ~16     !1, 'id'
         24        ASSIGN_DIM                                               !4, ~16
         25        OP_DATA                                                  !1
   43    26    >   INIT_ARRAY                                       ~18     !3
   44    27        ADD_ARRAY_ELEMENT                                ~18     !4
         28        VERIFY_RETURN_TYPE                                       ~18
         29      > RETURN                                                   ~18
   46    30*       VERIFY_RETURN_TYPE                                       
         31*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
125.66 ms | 962 KiB | 18 Q