3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array(); $meanax = 300; for($i = 0; $i < $meanax; $i++) { $array[$i] = rand(0, $meanax-1); echo $array[$i]."\n"; } $s = sd($array); $mean = array_sum($array) / count($array); echo "\nbefore\n"; var_dump(array('s' => $s, 'm' => $mean)); $n = count($array); $x_new = 100000000; $x_quer_strich = m_reverse($n, $mean, $x_new); $s_new = sd_reverse($s, $n, $x_new, $x_quer_strich); echo "\nreverse\n"; var_dump(array('s' => $s_new, 'm' => $x_quer_strich)); $array[$n+1] = $x_new; $s = sd($array); $mean = array_sum($array) / count($array); echo "\nafter\n"; var_dump(array('s' => $s, 'm' => $mean)); // Function to calculate square of value - mean function sd_square($x, $mean) { return pow($x - $mean,2); } // Function to calculate standard deviation (uses sd_square) function sd($array) { // square root of sum of squares devided by N-1 return sqrt(array_sum(array_map("sd_square", $array, array_fill(0,count($array), (array_sum($array) / count($array)) ) ) ) / (count($array)-1) ); } function m_reverse($n, $mean, $x) { return ( $n * $mean + $x ) / ( $n + 1 ); } function sd_reverse($s, $n, $x, $mean) { return sqrt( 1 / $n * ( ( $n - 1 ) * pow( $s, 2 ) + ( $x - $mean ) ) ); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 4
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 4
Branch analysis from position: 17
Branch analysis from position: 4
filename:       /in/2Weg5
function name:  (null)
number of ops:  75
compiled vars:  !0 = $array, !1 = $meanax, !2 = $i, !3 = $s, !4 = $mean, !5 = $n, !6 = $x_new, !7 = $x_quer_strich, !8 = $s_new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 300
    5     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->15
    6     4    >   INIT_FCALL                                               'rand'
          5        SEND_VAL                                                 0
          6        SUB                                              ~13     !1, 1
          7        SEND_VAL                                                 ~13
          8        DO_ICALL                                         $14     
          9        ASSIGN_DIM                                               !0, !2
         10        OP_DATA                                                  $14
    7    11        FETCH_DIM_R                                      ~15     !0, !2
         12        CONCAT                                           ~16     ~15, '%0A'
         13        ECHO                                                     ~16
    5    14        PRE_INC                                                  !2
         15    >   IS_SMALLER                                               !2, !1
         16      > JMPNZ                                                    ~18, ->4
   10    17    >   INIT_FCALL_BY_NAME                                       'sd'
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0  $19     
         20        ASSIGN                                                   !3, $19
   11    21        INIT_FCALL                                               'array_sum'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $21     
         24        COUNT                                            ~22     !0
         25        DIV                                              ~23     $21, ~22
         26        ASSIGN                                                   !4, ~23
   13    27        ECHO                                                     '%0Abefore%0A'
   14    28        INIT_FCALL                                               'var_dump'
         29        INIT_ARRAY                                       ~25     !3, 's'
         30        ADD_ARRAY_ELEMENT                                ~25     !4, 'm'
         31        SEND_VAL                                                 ~25
         32        DO_ICALL                                                 
   16    33        COUNT                                            ~27     !0
         34        ASSIGN                                                   !5, ~27
   18    35        ASSIGN                                                   !6, 100000000
   19    36        INIT_FCALL_BY_NAME                                       'm_reverse'
         37        SEND_VAR_EX                                              !5
         38        SEND_VAR_EX                                              !4
         39        SEND_VAR_EX                                              !6
         40        DO_FCALL                                      0  $30     
         41        ASSIGN                                                   !7, $30
   21    42        INIT_FCALL_BY_NAME                                       'sd_reverse'
         43        SEND_VAR_EX                                              !3
         44        SEND_VAR_EX                                              !5
         45        SEND_VAR_EX                                              !6
         46        SEND_VAR_EX                                              !7
         47        DO_FCALL                                      0  $32     
         48        ASSIGN                                                   !8, $32
   23    49        ECHO                                                     '%0Areverse%0A'
   24    50        INIT_FCALL                                               'var_dump'
         51        INIT_ARRAY                                       ~34     !8, 's'
         52        ADD_ARRAY_ELEMENT                                ~34     !7, 'm'
         53        SEND_VAL                                                 ~34
         54        DO_ICALL                                                 
   26    55        ADD                                              ~36     !5, 1
         56        ASSIGN_DIM                                               !0, ~36
         57        OP_DATA                                                  !6
   28    58        INIT_FCALL_BY_NAME                                       'sd'
         59        SEND_VAR_EX                                              !0
         60        DO_FCALL                                      0  $38     
         61        ASSIGN                                                   !3, $38
   29    62        INIT_FCALL                                               'array_sum'
         63        SEND_VAR                                                 !0
         64        DO_ICALL                                         $40     
         65        COUNT                                            ~41     !0
         66        DIV                                              ~42     $40, ~41
         67        ASSIGN                                                   !4, ~42
   31    68        ECHO                                                     '%0Aafter%0A'
   32    69        INIT_FCALL                                               'var_dump'
         70        INIT_ARRAY                                       ~44     !3, 's'
         71        ADD_ARRAY_ELEMENT                                ~44     !4, 'm'
         72        SEND_VAL                                                 ~44
         73        DO_ICALL                                                 
   49    74      > RETURN                                                   1

Function sd_square:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Weg5
function name:  sd_square
number of ops:  9
compiled vars:  !0 = $x, !1 = $mean
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'pow'
          3        SUB                                              ~2      !0, !1
          4        SEND_VAL                                                 ~2
          5        SEND_VAL                                                 2
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
          8*     > RETURN                                                   null

End of function sd_square

Function sd:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Weg5
function name:  sd
number of ops:  28
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   40     1        INIT_FCALL                                               'sqrt'
          2        INIT_FCALL                                               'array_sum'
          3        INIT_FCALL                                               'array_map'
          4        SEND_VAL                                                 'sd_square'
          5        SEND_VAR                                                 !0
          6        INIT_FCALL                                               'array_fill'
          7        SEND_VAL                                                 0
          8        COUNT                                            ~1      !0
          9        SEND_VAL                                                 ~1
         10        INIT_FCALL                                               'array_sum'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $2      
         13        COUNT                                            ~3      !0
         14        DIV                                              ~4      $2, ~3
         15        SEND_VAL                                                 ~4
         16        DO_ICALL                                         $5      
         17        SEND_VAR                                                 $5
         18        DO_ICALL                                         $6      
         19        SEND_VAR                                                 $6
         20        DO_ICALL                                         $7      
         21        COUNT                                            ~8      !0
         22        SUB                                              ~9      ~8, 1
         23        DIV                                              ~10     $7, ~9
         24        SEND_VAL                                                 ~10
         25        DO_ICALL                                         $11     
         26      > RETURN                                                   $11
   41    27*     > RETURN                                                   null

End of function sd

Function m_reverse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Weg5
function name:  m_reverse
number of ops:  9
compiled vars:  !0 = $n, !1 = $mean, !2 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   44     3        MUL                                              ~3      !0, !1
          4        ADD                                              ~4      ~3, !2
          5        ADD                                              ~5      !0, 1
          6        DIV                                              ~6      ~4, ~5
          7      > RETURN                                                   ~6
   45     8*     > RETURN                                                   null

End of function m_reverse

Function sd_reverse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2Weg5
function name:  sd_reverse
number of ops:  19
compiled vars:  !0 = $s, !1 = $n, !2 = $x, !3 = $mean
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   48     4        INIT_FCALL                                               'sqrt'
          5        DIV                                              ~4      1, !1
          6        SUB                                              ~5      !1, 1
          7        INIT_FCALL                                               'pow'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 2
         10        DO_ICALL                                         $6      
         11        MUL                                              ~7      $6, ~5
         12        SUB                                              ~8      !2, !3
         13        ADD                                              ~9      ~7, ~8
         14        MUL                                              ~10     ~4, ~9
         15        SEND_VAL                                                 ~10
         16        DO_ICALL                                         $11     
         17      > RETURN                                                   $11
   49    18*     > RETURN                                                   null

End of function sd_reverse

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.74 ms | 1408 KiB | 27 Q