3v4l.org

run code in 300+ PHP versions simultaneously
<?php $vyvoj_cien = array( 0 => 100, 1 => 110, 2 => 120, 3 => 130, 4 => 140, 5 => 150, 6 => 160, 7 => 170, 8 => 180, 9 => 190, 10 => 200, 11 => 185, 12 => 175, 13 => 165, 14 => 160, 15 => 160, 16 => 160, 17 => 160, 18 => 160, 19 => 160, ); // jednoduchy priemer function sma(array $data) { $count = count($data); if (!$count) $count = 1; return array_sum($data) / $count; } // exponencialny priemer function ema(array $data,$return_last_only = true) { $data = array_values($data); // preindexovanie pola ak by nahodou boli nejake kluce vynechane a pod. $multiplier = 2 / (1 + count($data)); for ($i=0; $i<count($data); $i++) { $prev = isset($data[$i-1]) ? $data[$i-1] : $data[$i]; $data[$i] = $data[$i] * $multiplier + $prev * (1 - $multiplier); } return $return_last_only ? end($data) : $data; } // dvojity exponencialny priemer function dema(array $data,$return_last_only = true) { $data = array_values($data); // preindexovanie pola ak by nahodou boli nejake kluce vynechane a pod. $ema1 = ema($data,false); $ema2 = ema($ema1,false); for ($i=0; $i<count($data); $i++) { $data[$i] = 2 * $ema1[$i] - $ema2[$i]; } return $return_last_only ? end($data) : $data; } // trojity exponencialny priemer function tema(array $data,$return_last_only = true) { $data = array_values($data); // preindexovanie pola ak by nahodou boli nejake kluce vynechane a pod. $ema1 = ema($data,false); $ema2 = ema($ema1,false); $ema3 = ema($ema2,false); for ($i=0; $i<count($data); $i++) { $data[$i] = (3*$ema1[$i] - 3*$ema2[$i]) + $ema3[$i]; } return $return_last_only ? end($data) : $data; } ///// VYSLEDKY ///// echo "Zdrojove data: " . implode(', ', $vyvoj_cien) . PHP_EOL; echo "Jednoduchy priemer dat: " . sma($vyvoj_cien) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KumPO
function name:  (null)
number of ops:  15
compiled vars:  !0 = $vyvoj_cien
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   82     1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 '%2C+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        CONCAT                                           ~3      'Zdrojove+data%3A++', $2
          6        CONCAT                                           ~4      ~3, '%0A'
          7        ECHO                                                     ~4
   83     8        INIT_FCALL                                               'sma'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $5      
         11        CONCAT                                           ~6      'Jednoduchy+priemer+dat%3A+', $5
         12        CONCAT                                           ~7      ~6, '%0A'
         13        ECHO                                                     ~7
         14      > RETURN                                                   1

Function sma:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/KumPO
function name:  sma
number of ops:  12
compiled vars:  !0 = $data, !1 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        COUNT                                            ~2      !0
          2        ASSIGN                                                   !1, ~2
   31     3        BOOL_NOT                                         ~4      !1
          4      > JMPZ                                                     ~4, ->6
          5    >   ASSIGN                                                   !1, 1
   32     6    >   INIT_FCALL                                               'array_sum'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $6      
          9        DIV                                              ~7      $6, !1
         10      > RETURN                                                   ~7
   33    11*     > RETURN                                                   null

End of function sma

Function ema:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 39
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
Branch analysis from position: 12
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
Branch analysis from position: 12
filename:       /in/KumPO
function name:  ema
number of ops:  42
compiled vars:  !0 = $data, !1 = $return_last_only, !2 = $multiplier, !3 = $i, !4 = $prev
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
   39     2        INIT_FCALL                                               'array_values'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !0, $5
   40     6        COUNT                                            ~7      !0
          7        ADD                                              ~8      1, ~7
          8        DIV                                              ~9      2, ~8
          9        ASSIGN                                                   !2, ~9
   41    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->30
   42    12    >   SUB                                              ~12     !3, 1
         13        ISSET_ISEMPTY_DIM_OBJ                         0          !0, ~12
         14      > JMPZ                                                     ~13, ->19
         15    >   SUB                                              ~14     !3, 1
         16        FETCH_DIM_R                                      ~15     !0, ~14
         17        QM_ASSIGN                                        ~16     ~15
         18      > JMP                                                      ->21
         19    >   FETCH_DIM_R                                      ~17     !0, !3
         20        QM_ASSIGN                                        ~16     ~17
         21    >   ASSIGN                                                   !4, ~16
   43    22        FETCH_DIM_R                                      ~20     !0, !3
         23        MUL                                              ~21     !2, ~20
         24        SUB                                              ~22     1, !2
         25        MUL                                              ~23     !4, ~22
         26        ADD                                              ~24     ~21, ~23
         27        ASSIGN_DIM                                               !0, !3
         28        OP_DATA                                                  ~24
   41    29        PRE_INC                                                  !3
         30    >   COUNT                                            ~26     !0
         31        IS_SMALLER                                               !3, ~26
         32      > JMPNZ                                                    ~27, ->12
   45    33    > > JMPZ                                                     !1, ->39
         34    >   INIT_FCALL                                               'end'
         35        SEND_REF                                                 !0
         36        DO_ICALL                                         $28     
         37        QM_ASSIGN                                        ~29     $28
         38      > JMP                                                      ->40
         39    >   QM_ASSIGN                                        ~29     !0
         40    > > RETURN                                                   ~29
   46    41*     > RETURN                                                   null

End of function ema

Function dema:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 18
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 18
Branch analysis from position: 28
Branch analysis from position: 18
filename:       /in/KumPO
function name:  dema
number of ops:  37
compiled vars:  !0 = $data, !1 = $return_last_only, !2 = $ema1, !3 = $ema2, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
   52     2        INIT_FCALL                                               'array_values'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !0, $5
   53     6        INIT_FCALL                                               'ema'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 <false>
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !2, $7
   54    11        INIT_FCALL                                               'ema'
         12        SEND_VAR                                                 !2
         13        SEND_VAL                                                 <false>
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !3, $9
   56    16        ASSIGN                                                   !4, 0
         17      > JMP                                                      ->25
   57    18    >   FETCH_DIM_R                                      ~13     !2, !4
         19        MUL                                              ~14     ~13, 2
         20        FETCH_DIM_R                                      ~15     !3, !4
         21        SUB                                              ~16     ~14, ~15
         22        ASSIGN_DIM                                               !0, !4
         23        OP_DATA                                                  ~16
   56    24        PRE_INC                                                  !4
         25    >   COUNT                                            ~18     !0
         26        IS_SMALLER                                               !4, ~18
         27      > JMPNZ                                                    ~19, ->18
   60    28    > > JMPZ                                                     !1, ->34
         29    >   INIT_FCALL                                               'end'
         30        SEND_REF                                                 !0
         31        DO_ICALL                                         $20     
         32        QM_ASSIGN                                        ~21     $20
         33      > JMP                                                      ->35
         34    >   QM_ASSIGN                                        ~21     !0
         35    > > RETURN                                                   ~21
   61    36*     > RETURN                                                   null

End of function dema

Function tema:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 23
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 42
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 23
Branch analysis from position: 36
Branch analysis from position: 23
filename:       /in/KumPO
function name:  tema
number of ops:  45
compiled vars:  !0 = $data, !1 = $return_last_only, !2 = $ema1, !3 = $ema2, !4 = $ema3, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
   67     2        INIT_FCALL                                               'array_values'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !0, $6
   68     6        INIT_FCALL                                               'ema'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 <false>
          9        DO_FCALL                                      0  $8      
         10        ASSIGN                                                   !2, $8
   69    11        INIT_FCALL                                               'ema'
         12        SEND_VAR                                                 !2
         13        SEND_VAL                                                 <false>
         14        DO_FCALL                                      0  $10     
         15        ASSIGN                                                   !3, $10
   70    16        INIT_FCALL                                               'ema'
         17        SEND_VAR                                                 !3
         18        SEND_VAL                                                 <false>
         19        DO_FCALL                                      0  $12     
         20        ASSIGN                                                   !4, $12
   72    21        ASSIGN                                                   !5, 0
         22      > JMP                                                      ->33
   73    23    >   FETCH_DIM_R                                      ~16     !2, !5
         24        MUL                                              ~17     ~16, 3
         25        FETCH_DIM_R                                      ~18     !3, !5
         26        MUL                                              ~19     ~18, 3
         27        SUB                                              ~20     ~17, ~19
         28        FETCH_DIM_R                                      ~21     !4, !5
         29        ADD                                              ~22     ~20, ~21
         30        ASSIGN_DIM                                               !0, !5
         31        OP_DATA                                                  ~22
   72    32        PRE_INC                                                  !5
         33    >   COUNT                                            ~24     !0
         34        IS_SMALLER                                               !5, ~24
         35      > JMPNZ                                                    ~25, ->23
   76    36    > > JMPZ                                                     !1, ->42
         37    >   INIT_FCALL                                               'end'
         38        SEND_REF                                                 !0
         39        DO_ICALL                                         $26     
         40        QM_ASSIGN                                        ~27     $26
         41      > JMP                                                      ->43
         42    >   QM_ASSIGN                                        ~27     !0
         43    > > RETURN                                                   ~27
   77    44*     > RETURN                                                   null

End of function tema

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.83 ms | 1415 KiB | 27 Q