3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pizzas = [ ['cheese', 'tomato', 'ham', 'beef', 'pineapple'], ['bacon', 'ham', 'cheese'], ['cheese', 'tomato', 'bacon', 'chili', 'salad'], ['tomato', 'salad', 'pineapple'], ['tomato', 'beef', 'bacon'], ['cheese', 'tomato', 'bacon', 'chili', 'salad', 'anchovies'], ['tomato', 'pineapple', 'bacon', 'cheese', 'ham'], ]; $included_wish = ['cheese', 'ham', 'bacon']; $excluded_wish = ['pineapple']; $percentages = []; $wishCount = count($included_wish); foreach ($pizzas as $pizza) { if (array_intersect($excluded_wish, $pizza)) { continue; } $result[] = [ 'perc' => count(array_intersect($included_wish, $pizza)) / $wishCount, 'additional' => count(array_diff($pizza, $included_wish)), 'ingredients' => implode(', ', $pizza), ]; } usort($result, fn($a, $b) => [$b['perc'], $a['additional']] <=> [$a['perc'], $b['additional']]); foreach ($result as $row) { vprintf("wished: %.02f%%, surplus toppings: %d : %s\n", $row); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 35
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 42, Position 2 = 48
Branch analysis from position: 42
2 jumps found. (Code = 78) Position 1 = 43, Position 2 = 48
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
Branch analysis from position: 35
filename:       /in/8OmFU
function name:  (null)
number of ops:  50
compiled vars:  !0 = $pizzas, !1 = $included_wish, !2 = $excluded_wish, !3 = $percentages, !4 = $wishCount, !5 = $pizza, !6 = $result, !7 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   13     1        ASSIGN                                                   !1, <array>
   14     2        ASSIGN                                                   !2, <array>
   16     3        ASSIGN                                                   !3, <array>
   17     4        COUNT                                            ~12     !1
          5        ASSIGN                                                   !4, ~12
   18     6      > FE_RESET_R                                       $14     !0, ->35
          7    > > FE_FETCH_R                                               $14, !5, ->35
   19     8    >   INIT_FCALL                                               'array_intersect'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !5
         11        DO_ICALL                                         $15     
         12      > JMPZ                                                     $15, ->14
   20    13    > > JMP                                                      ->7
   23    14    >   INIT_FCALL                                               'array_intersect'
         15        SEND_VAR                                                 !1
         16        SEND_VAR                                                 !5
         17        DO_ICALL                                         $17     
         18        COUNT                                            ~18     $17
         19        DIV                                              ~19     ~18, !4
         20        INIT_ARRAY                                       ~20     ~19, 'perc'
   24    21        INIT_FCALL                                               'array_diff'
         22        SEND_VAR                                                 !5
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $21     
         25        COUNT                                            ~22     $21
         26        ADD_ARRAY_ELEMENT                                ~20     ~22, 'additional'
   25    27        INIT_FCALL                                               'implode'
         28        SEND_VAL                                                 '%2C+'
         29        SEND_VAR                                                 !5
         30        DO_ICALL                                         $23     
         31        ADD_ARRAY_ELEMENT                                ~20     $23, 'ingredients'
   22    32        ASSIGN_DIM                                               !6
   25    33        OP_DATA                                                  ~20
   18    34      > JMP                                                      ->7
         35    >   FE_FREE                                                  $14
   29    36        INIT_FCALL                                               'usort'
         37        SEND_REF                                                 !6
         38        DECLARE_LAMBDA_FUNCTION                          ~24     [0]
         39        SEND_VAL                                                 ~24
         40        DO_ICALL                                                 
   30    41      > FE_RESET_R                                       $26     !6, ->48
         42    > > FE_FETCH_R                                               $26, !7, ->48
   31    43    >   INIT_FCALL                                               'vprintf'
         44        SEND_VAL                                                 'wished%3A+%25.02f%25%25%2C+surplus+toppings%3A+%25d+%3A+%25s%0A'
         45        SEND_VAR                                                 !7
         46        DO_ICALL                                                 
   30    47      > JMP                                                      ->42
         48    >   FE_FREE                                                  $26
   32    49      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8OmFU
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        FETCH_DIM_R                                      ~2      !1, 'perc'
          3        INIT_ARRAY                                       ~3      ~2
          4        FETCH_DIM_R                                      ~4      !0, 'additional'
          5        ADD_ARRAY_ELEMENT                                ~3      ~4
          6        FETCH_DIM_R                                      ~5      !0, 'perc'
          7        INIT_ARRAY                                       ~6      ~5
          8        FETCH_DIM_R                                      ~7      !1, 'additional'
          9        ADD_ARRAY_ELEMENT                                ~6      ~7
         10        SPACESHIP                                        ~8      ~3, ~6
         11      > RETURN                                                   ~8
         12*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.91 ms | 1019 KiB | 18 Q