3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mkProductList($array) { // $tmpVal get product of all elements $tmpVal = 1; // Count zeros in array $cnt = count(array_keys($array, 0)); // If there are two or more zeros, then product of all elements will be zero // No make sense to do // Fill array with zeros and return it if ($cnt > 1) { $array = array_fill_keys(array_keys($array), 0); return $array; } // If there are one or no zeros, then get product of all elements, exclude zero, // cause multiply by zero equal zero foreach($array as $value) { if ($value != 0) { $tmpVal *= $value; } } // If there are one zero, then product of all elements will be zero // exclude zero position in input array, it will be product of all elements if ($cnt == 1) { $array = array_fill_keys(array_keys($array), 0); $array[array_search(0, $array)] = $tmpVal; return $array; } // If there are no zeros, then we replace velues in input array // Product of all elements we devide by current element value // Result is product of all elements, exclude current element value foreach($array as $key => $value) { $array[$key] = $tmpVal / $value; } return $array; } // tests var_dump(producePatStr(array(1,2,3,4))); var_dump(producePatStr(array())); var_dump(producePatStr(array(-0.5, 100, 20))); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QKK25
function name:  (null)
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL_BY_NAME                                       'producePatStr'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   47     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL_BY_NAME                                       'producePatStr'
          8        SEND_VAL_EX                                              <array>
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   48    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL_BY_NAME                                       'producePatStr'
         14        SEND_VAL_EX                                              <array>
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                                 
   49    18      > RETURN                                                   1

Function mkproductlist:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 24
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 43
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 50
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 25
filename:       /in/QKK25
function name:  mkProductList
number of ops:  53
compiled vars:  !0 = $array, !1 = $tmpVal, !2 = $cnt, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, 1
    8     2        INIT_FCALL                                               'array_keys'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        DO_ICALL                                         $6      
          6        COUNT                                            ~7      $6
          7        ASSIGN                                                   !2, ~7
   13     8        IS_SMALLER                                               1, !2
          9      > JMPZ                                                     ~9, ->19
   14    10    >   INIT_FCALL                                               'array_fill_keys'
         11        INIT_FCALL                                               'array_keys'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $10     
         14        SEND_VAR                                                 $10
         15        SEND_VAL                                                 0
         16        DO_ICALL                                         $11     
         17        ASSIGN                                                   !0, $11
   15    18      > RETURN                                                   !0
   20    19    > > FE_RESET_R                                       $13     !0, ->25
         20    > > FE_FETCH_R                                               $13, !3, ->25
   21    21    >   IS_NOT_EQUAL                                             !3, 0
         22      > JMPZ                                                     ~14, ->24
   22    23    >   ASSIGN_OP                                     3          !1, !3
   20    24    > > JMP                                                      ->20
         25    >   FE_FREE                                                  $13
   28    26        IS_EQUAL                                                 !2, 1
         27      > JMPZ                                                     ~16, ->43
   29    28    >   INIT_FCALL                                               'array_fill_keys'
         29        INIT_FCALL                                               'array_keys'
         30        SEND_VAR                                                 !0
         31        DO_ICALL                                         $17     
         32        SEND_VAR                                                 $17
         33        SEND_VAL                                                 0
         34        DO_ICALL                                         $18     
         35        ASSIGN                                                   !0, $18
   30    36        INIT_FCALL                                               'array_search'
         37        SEND_VAL                                                 0
         38        SEND_VAR                                                 !0
         39        DO_ICALL                                         $20     
         40        ASSIGN_DIM                                               !0, $20
         41        OP_DATA                                                  !1
   31    42      > RETURN                                                   !0
   37    43    > > FE_RESET_R                                       $22     !0, ->50
         44    > > FE_FETCH_R                                       ~23     $22, !3, ->50
         45    >   ASSIGN                                                   !4, ~23
   38    46        DIV                                              ~26     !1, !3
         47        ASSIGN_DIM                                               !0, !4
         48        OP_DATA                                                  ~26
   37    49      > JMP                                                      ->44
         50    >   FE_FREE                                                  $22
   41    51      > RETURN                                                   !0
   42    52*     > RETURN                                                   null

End of function mkproductlist

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.92 ms | 1400 KiB | 21 Q