3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array(9,4,-3,-10); function stddev($array){ //Don Knuth is the $deity of algorithms //http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#III._On-line_algorithm $n = 0; $mean = 0; $M2 = 0; foreach($array as $x){ $n++; $delta = $x - $mean; $mean = $mean + $delta/$n; $M2 = $M2 + $delta*($x - $mean); } $variance = $M2/($n - 1); return sqrt($variance); } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHQOT
function name:  (null)
number of ops:  2
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   19     1      > RETURN                                                   1

Function stddev:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 17
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/NHQOT
function name:  stddev
number of ops:  26
compiled vars:  !0 = $array, !1 = $n, !2 = $mean, !3 = $M2, !4 = $x, !5 = $delta, !6 = $variance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    7     1        ASSIGN                                                   !1, 0
    8     2        ASSIGN                                                   !2, 0
    9     3        ASSIGN                                                   !3, 0
   10     4      > FE_RESET_R                                       $10     !0, ->17
          5    > > FE_FETCH_R                                               $10, !4, ->17
   11     6    >   PRE_INC                                                  !1
   12     7        SUB                                              ~12     !4, !2
          8        ASSIGN                                                   !5, ~12
   13     9        DIV                                              ~14     !5, !1
         10        ADD                                              ~15     !2, ~14
         11        ASSIGN                                                   !2, ~15
   14    12        SUB                                              ~17     !4, !2
         13        MUL                                              ~18     !5, ~17
         14        ADD                                              ~19     !3, ~18
         15        ASSIGN                                                   !3, ~19
   10    16      > JMP                                                      ->5
         17    >   FE_FREE                                                  $10
   16    18        SUB                                              ~21     !1, 1
         19        DIV                                              ~22     !3, ~21
         20        ASSIGN                                                   !6, ~22
   17    21        INIT_FCALL                                               'sqrt'
         22        SEND_VAR                                                 !6
         23        DO_ICALL                                         $24     
         24      > RETURN                                                   $24
   18    25*     > RETURN                                                   null

End of function stddev

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.47 ms | 1396 KiB | 15 Q