3v4l.org

run code in 300+ PHP versions simultaneously
<?php $PopulationOfTexas = array( 1999 => 20.56, // in millions 2000 => 21.56, 2001 => 22.56, 2002 => 23.56 ); //generate an array sohwing the difference in each year compared to the previous year $differneces = array(); $lastmonth = null; foreach($PopulationOfTexas as $k=>$v){ if(empty($lastmonth)){$lastmonth = $k; continue;} $differneces[$k] = $k - $lastmonth; $lastmonth = $k; //use this later $lastitem = array("year"=>$k, "data"=>$v); } //print_r($differneces); //get the average difference per year $count = 0; $total = 0; foreach($differneces as $k=>$v){ $count++; $total += $v; } $average = number_format(($total/$count), 2); //print_r($average); //make a prediction print_r($lastitem);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 18
filename:       /in/SXYLk
function name:  (null)
number of ops:  38
compiled vars:  !0 = $PopulationOfTexas, !1 = $differneces, !2 = $lastmonth, !3 = $v, !4 = $k, !5 = $lastitem, !6 = $count, !7 = $total, !8 = $average
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2        ASSIGN                                                   !2, null
   13     3      > FE_RESET_R                                       $12     !0, ->18
          4    > > FE_FETCH_R                                       ~13     $12, !3, ->18
          5    >   ASSIGN                                                   !4, ~13
   14     6        ISSET_ISEMPTY_CV                                         !2
          7      > JMPZ                                                     ~15, ->10
          8    >   ASSIGN                                                   !2, !4
          9      > JMP                                                      ->4
   15    10    >   SUB                                              ~18     !4, !2
         11        ASSIGN_DIM                                               !1, !4
         12        OP_DATA                                                  ~18
   16    13        ASSIGN                                                   !2, !4
   19    14        INIT_ARRAY                                       ~20     !4, 'year'
         15        ADD_ARRAY_ELEMENT                                ~20     !3, 'data'
         16        ASSIGN                                                   !5, ~20
   13    17      > JMP                                                      ->4
         18    >   FE_FREE                                                  $12
   25    19        ASSIGN                                                   !6, 0
   26    20        ASSIGN                                                   !7, 0
   27    21      > FE_RESET_R                                       $24     !1, ->27
         22    > > FE_FETCH_R                                       ~25     $24, !3, ->27
         23    >   ASSIGN                                                   !4, ~25
   28    24        PRE_INC                                                  !6
   29    25        ASSIGN_OP                                     1          !7, !3
   27    26      > JMP                                                      ->22
         27    >   FE_FREE                                                  $24
   32    28        INIT_FCALL                                               'number_format'
         29        DIV                                              ~29     !7, !6
         30        SEND_VAL                                                 ~29
         31        SEND_VAL                                                 2
         32        DO_ICALL                                         $30     
         33        ASSIGN                                                   !8, $30
   37    34        INIT_FCALL                                               'print_r'
         35        SEND_VAR                                                 !5
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.53 ms | 1400 KiB | 17 Q