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, ], ]; function mySort(array $canonicalIds, array $putContent): array { $toCreate = $toUpdate = []; foreach ($putContent as $putItem) { if (null === $putItem['id']) { $toCreate[] = $putItem; } elseif (in_array($putItem['id'], $canonicalIds, true) === true) { $toUpdate[] = $putItem; } } $toDelete = array_diff($canonicalIds, array_column($toUpdate, 'id')); return [$toCreate, $toUpdate, $toDelete]; } [$toCreate, $toUpdate, $toDelete] = mySort($canonicalIds, $putContent); var_dump($toCreate, $toUpdate, $toDelete);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuAgX
function name:  (null)
number of ops:  19
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>
   48     2        INIT_FCALL                                                   'mysort'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0  $7      
          6        FETCH_LIST_R                                         $8      $7, 0
          7        ASSIGN                                                       !2, $8
          8        FETCH_LIST_R                                         $10     $7, 1
          9        ASSIGN                                                       !3, $10
         10        FETCH_LIST_R                                         $12     $7, 2
         11        ASSIGN                                                       !4, $12
         12        FREE                                                         $7
   50    13        INIT_FCALL                                                   'var_dump'
         14        SEND_VAR                                                     !2
         15        SEND_VAR                                                     !3
         16        SEND_VAR                                                     !4
         17        DO_ICALL                                                     
         18      > RETURN                                                       1

Function mysort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
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 = 5
Branch analysis from position: 5
Branch analysis from position: 19
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/OuAgX
function name:  mySort
number of ops:  37
compiled vars:  !0 = $canonicalIds, !1 = $putContent, !2 = $toCreate, !3 = $toUpdate, !4 = $putItem, !5 = $toDelete
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   33     2        ASSIGN                                               ~6      !3, <array>
          3        ASSIGN                                                       !2, ~6
   35     4      > FE_RESET_R                                           $8      !1, ->20
          5    > > FE_FETCH_R                                                   $8, !4, ->20
   36     6    >   FETCH_DIM_R                                          ~9      !4, 'id'
          7        TYPE_CHECK                                        2          ~9
          8      > JMPZ                                                         ~10, ->12
   37     9    >   ASSIGN_DIM                                                   !2
         10        OP_DATA                                                      !4
   36    11      > JMP                                                          ->19
   38    12    >   FETCH_DIM_R                                          ~12     !4, 'id'
         13        FRAMELESS_ICALL_3                in_array            ~13     ~12, !0
         14        OP_DATA                                                      <true>
         15        TYPE_CHECK                                        8          ~13
         16      > JMPZ                                                         ~14, ->19
   39    17    >   ASSIGN_DIM                                                   !3
         18        OP_DATA                                                      !4
   35    19    > > JMP                                                          ->5
         20    >   FE_FREE                                                      $8
   43    21        INIT_FCALL                                                   'array_diff'
         22        SEND_VAR                                                     !0
         23        INIT_FCALL                                                   'array_column'
         24        SEND_VAR                                                     !3
         25        SEND_VAL                                                     'id'
         26        DO_ICALL                                             $16     
         27        SEND_VAR                                                     $16
         28        DO_ICALL                                             $17     
         29        ASSIGN                                                       !5, $17
   45    30        INIT_ARRAY                                           ~19     !2
         31        ADD_ARRAY_ELEMENT                                    ~19     !3
         32        ADD_ARRAY_ELEMENT                                    ~19     !5
         33        VERIFY_RETURN_TYPE                                           ~19
         34      > RETURN                                                       ~19
   46    35*       VERIFY_RETURN_TYPE                                           
         36*     > RETURN                                                       null

End of function mysort

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
175.51 ms | 1892 KiB | 17 Q