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 = array_filter($putContent, static function (array $item): bool { return null === $item['id']; }); $toUpdate = array_uintersect( $putContent, array_map(static function (string $id): array { return ['id' => $id]; }, $canonicalIds), static function (array $putItem, array $canonicalItem): int { return $putItem['id'] <=> $canonicalItem['id']; } ); $toDelete = array_diff($canonicalIds, array_column($toUpdate, 'id')); var_dump($toCreate, $toUpdate, $toDelete);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lp2E7
function name:  (null)
number of ops:  35
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_filter'
          3        SEND_VAR                                                 !1
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Flp2E7%3A31%240'
   33     5        SEND_VAL                                                 ~7
          6        DO_ICALL                                         $8      
   31     7        ASSIGN                                                   !2, $8
   35     8        INIT_FCALL                                               'array_uintersect'
   36     9        SEND_VAR                                                 !1
   37    10        INIT_FCALL                                               'array_map'
         11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Flp2E7%3A37%241'
   39    12        SEND_VAL                                                 ~10
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $11     
         15        SEND_VAR                                                 $11
   40    16        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Flp2E7%3A40%242'
   42    17        SEND_VAL                                                 ~12
         18        DO_ICALL                                         $13     
   35    19        ASSIGN                                                   !3, $13
   45    20        INIT_FCALL                                               'array_diff'
         21        SEND_VAR                                                 !0
         22        INIT_FCALL                                               'array_column'
         23        SEND_VAR                                                 !3
         24        SEND_VAL                                                 'id'
         25        DO_ICALL                                         $15     
         26        SEND_VAR                                                 $15
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !4, $16
   47    29        INIT_FCALL                                               'var_dump'
         30        SEND_VAR                                                 !2
         31        SEND_VAR                                                 !3
         32        SEND_VAR                                                 !4
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Flp2E7%3A31%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lp2E7
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        FETCH_DIM_R                                      ~1      !0, 'id'
          2        TYPE_CHECK                                    2  ~2      ~1
          3        VERIFY_RETURN_TYPE                                       ~2
          4      > RETURN                                                   ~2
   33     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Flp2E7%3A31%240

Function %00%7Bclosure%7D%2Fin%2Flp2E7%3A37%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lp2E7
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   38     1        INIT_ARRAY                                       ~1      !0, 'id'
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   39     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Flp2E7%3A37%241

Function %00%7Bclosure%7D%2Fin%2Flp2E7%3A40%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lp2E7
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $putItem, !1 = $canonicalItem
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   41     2        FETCH_DIM_R                                      ~2      !0, 'id'
          3        FETCH_DIM_R                                      ~3      !1, 'id'
          4        SPACESHIP                                        ~4      ~2, ~3
          5        VERIFY_RETURN_TYPE                                       ~4
          6      > RETURN                                                   ~4
   42     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Flp2E7%3A40%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.93 ms | 1411 KiB | 25 Q