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); } $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)); echo "\nvalues array\n"; var_dump($array); // 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 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 4
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 4
Branch analysis from position: 14
Branch analysis from position: 4
filename:       /in/5mPDp
function name:  (null)
number of ops:  76
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                                                      ->12
    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
    5    11        PRE_INC                                                  !2
         12    >   IS_SMALLER                                               !2, !1
         13      > JMPNZ                                                    ~16, ->4
    9    14    >   INIT_FCALL_BY_NAME                                       'sd'
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0  $17     
         17        ASSIGN                                                   !3, $17
   10    18        INIT_FCALL                                               'array_sum'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $19     
         21        COUNT                                            ~20     !0
         22        DIV                                              ~21     $19, ~20
         23        ASSIGN                                                   !4, ~21
   12    24        ECHO                                                     '%0Abefore%0A'
   13    25        INIT_FCALL                                               'var_dump'
         26        INIT_ARRAY                                       ~23     !3, 's'
         27        ADD_ARRAY_ELEMENT                                ~23     !4, 'm'
         28        SEND_VAL                                                 ~23
         29        DO_ICALL                                                 
   15    30        COUNT                                            ~25     !0
         31        ASSIGN                                                   !5, ~25
   17    32        ASSIGN                                                   !6, 100000000
   18    33        INIT_FCALL_BY_NAME                                       'm_reverse'
         34        SEND_VAR_EX                                              !5
         35        SEND_VAR_EX                                              !4
         36        SEND_VAR_EX                                              !6
         37        DO_FCALL                                      0  $28     
         38        ASSIGN                                                   !7, $28
   20    39        INIT_FCALL_BY_NAME                                       'sd_reverse'
         40        SEND_VAR_EX                                              !3
         41        SEND_VAR_EX                                              !5
         42        SEND_VAR_EX                                              !6
         43        SEND_VAR_EX                                              !7
         44        DO_FCALL                                      0  $30     
         45        ASSIGN                                                   !8, $30
   22    46        ECHO                                                     '%0Areverse%0A'
   23    47        INIT_FCALL                                               'var_dump'
         48        INIT_ARRAY                                       ~32     !8, 's'
         49        ADD_ARRAY_ELEMENT                                ~32     !7, 'm'
         50        SEND_VAL                                                 ~32
         51        DO_ICALL                                                 
   25    52        ADD                                              ~34     !5, 1
         53        ASSIGN_DIM                                               !0, ~34
         54        OP_DATA                                                  !6
   27    55        INIT_FCALL_BY_NAME                                       'sd'
         56        SEND_VAR_EX                                              !0
         57        DO_FCALL                                      0  $36     
         58        ASSIGN                                                   !3, $36
   28    59        INIT_FCALL                                               'array_sum'
         60        SEND_VAR                                                 !0
         61        DO_ICALL                                         $38     
         62        COUNT                                            ~39     !0
         63        DIV                                              ~40     $38, ~39
         64        ASSIGN                                                   !4, ~40
   30    65        ECHO                                                     '%0Aafter%0A'
   31    66        INIT_FCALL                                               'var_dump'
         67        INIT_ARRAY                                       ~42     !3, 's'
         68        ADD_ARRAY_ELEMENT                                ~42     !4, 'm'
         69        SEND_VAL                                                 ~42
         70        DO_ICALL                                                 
   33    71        ECHO                                                     '%0Avalues+array%0A'
   34    72        INIT_FCALL                                               'var_dump'
         73        SEND_VAR                                                 !0
         74        DO_ICALL                                                 
   51    75      > RETURN                                                   1

Function sd_square:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5mPDp
function name:  sd_square
number of ops:  9
compiled vars:  !0 = $x, !1 = $mean
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     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/5mPDp
function name:  sd
number of ops:  28
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     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
   43    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/5mPDp
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
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   46     3        MUL                                              ~3      !0, !1
          4        ADD                                              ~4      ~3, !2
          5        ADD                                              ~5      !0, 1
          6        DIV                                              ~6      ~4, ~5
          7      > RETURN                                                   ~6
   47     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/5mPDp
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
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   50     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
   51    18*     > RETURN                                                   null

End of function sd_reverse

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.63 ms | 1408 KiB | 27 Q