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, ], ]; 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 = 23
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 23
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 = 22
Branch analysis from position: 22
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 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 22
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/OuAgX
function name:  mySort
number of ops:  40
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, ->23
          5    > > FE_FETCH_R                                               $8, !4, ->23
   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                                                      ->22
   38    12    >   INIT_FCALL                                               'in_array'
         13        FETCH_DIM_R                                      ~12     !4, 'id'
         14        SEND_VAL                                                 ~12
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $13     
         18        TYPE_CHECK                                    8          $13
         19      > JMPZ                                                     ~14, ->22
   39    20    >   ASSIGN_DIM                                               !3
         21        OP_DATA                                                  !4
   35    22    > > JMP                                                      ->5
         23    >   FE_FREE                                                  $8
   43    24        INIT_FCALL                                               'array_diff'
         25        SEND_VAR                                                 !0
         26        INIT_FCALL                                               'array_column'
         27        SEND_VAR                                                 !3
         28        SEND_VAL                                                 'id'
         29        DO_ICALL                                         $16     
         30        SEND_VAR                                                 $16
         31        DO_ICALL                                         $17     
         32        ASSIGN                                                   !5, $17
   45    33        INIT_ARRAY                                       ~19     !2
         34        ADD_ARRAY_ELEMENT                                ~19     !3
         35        ADD_ARRAY_ELEMENT                                ~19     !5
         36        VERIFY_RETURN_TYPE                                       ~19
         37      > RETURN                                                   ~19
   46    38*       VERIFY_RETURN_TYPE                                       
         39*     > RETURN                                                   null

End of function mysort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.38 ms | 1447 KiB | 18 Q