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(); $lastyear = null; foreach($PopulationOfTexas as $k=>$v){ if(empty($lastyear)){$lastyear = $k; continue;} $differneces[$k] = $k - $lastyear; $lastyear = $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 $predictions = array(); for($i=0;$i<4;$i++){ $year = isset($year) ? $year+1 : $lastitem["year"]+1; $prediction = isset($prediction) ? $prediction+floatval($average) : $lastitem["data"]+floatval($average); $predictions[$year] = $prediction; } print_r($predictions);
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 = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 37
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 42
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 52
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 37
Branch analysis from position: 62
Branch analysis from position: 37
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 37
Branch analysis from position: 62
Branch analysis from position: 37
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 52
Branch analysis from position: 48
Branch analysis from position: 52
Branch analysis from position: 27
Branch analysis from position: 18
filename:       /in/RGU3i
function name:  (null)
number of ops:  66
compiled vars:  !0 = $PopulationOfTexas, !1 = $differneces, !2 = $lastyear, !3 = $v, !4 = $k, !5 = $lastitem, !6 = $count, !7 = $total, !8 = $average, !9 = $predictions, !10 = $i, !11 = $year, !12 = $prediction
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                                       $16     !0, ->18
          4    > > FE_FETCH_R                                       ~17     $16, !3, ->18
          5    >   ASSIGN                                                   !4, ~17
   14     6        ISSET_ISEMPTY_CV                                         !2
          7      > JMPZ                                                     ~19, ->10
          8    >   ASSIGN                                                   !2, !4
          9      > JMP                                                      ->4
   15    10    >   SUB                                              ~22     !4, !2
         11        ASSIGN_DIM                                               !1, !4
         12        OP_DATA                                                  ~22
   16    13        ASSIGN                                                   !2, !4
   19    14        INIT_ARRAY                                       ~24     !4, 'year'
         15        ADD_ARRAY_ELEMENT                                ~24     !3, 'data'
         16        ASSIGN                                                   !5, ~24
   13    17      > JMP                                                      ->4
         18    >   FE_FREE                                                  $16
   25    19        ASSIGN                                                   !6, 0
   26    20        ASSIGN                                                   !7, 0
   27    21      > FE_RESET_R                                       $28     !1, ->27
         22    > > FE_FETCH_R                                       ~29     $28, !3, ->27
         23    >   ASSIGN                                                   !4, ~29
   28    24        PRE_INC                                                  !6
   29    25        ASSIGN_OP                                     1          !7, !3
   27    26      > JMP                                                      ->22
         27    >   FE_FREE                                                  $28
   32    28        INIT_FCALL                                               'number_format'
         29        DIV                                              ~33     !7, !6
         30        SEND_VAL                                                 ~33
         31        SEND_VAL                                                 2
         32        DO_ICALL                                         $34     
         33        ASSIGN                                                   !8, $34
   37    34        ASSIGN                                                   !9, <array>
   38    35        ASSIGN                                                   !10, 0
         36      > JMP                                                      ->60
   39    37    >   ISSET_ISEMPTY_CV                                         !11
         38      > JMPZ                                                     ~38, ->42
         39    >   ADD                                              ~39     !11, 1
         40        QM_ASSIGN                                        ~40     ~39
         41      > JMP                                                      ->45
         42    >   FETCH_DIM_R                                      ~41     !5, 'year'
         43        ADD                                              ~42     ~41, 1
         44        QM_ASSIGN                                        ~40     ~42
         45    >   ASSIGN                                                   !11, ~40
   40    46        ISSET_ISEMPTY_CV                                         !12
         47      > JMPZ                                                     ~44, ->52
         48    >   CAST                                          5  ~45     !8
         49        ADD                                              ~46     !12, ~45
         50        QM_ASSIGN                                        ~47     ~46
         51      > JMP                                                      ->56
         52    >   FETCH_DIM_R                                      ~48     !5, 'data'
         53        CAST                                          5  ~49     !8
         54        ADD                                              ~50     ~48, ~49
         55        QM_ASSIGN                                        ~47     ~50
         56    >   ASSIGN                                                   !12, ~47
   41    57        ASSIGN_DIM                                               !9, !11
         58        OP_DATA                                                  !12
   38    59        PRE_INC                                                  !10
         60    >   IS_SMALLER                                               !10, 4
         61      > JMPNZ                                                    ~54, ->37
   44    62    >   INIT_FCALL                                               'print_r'
         63        SEND_VAR                                                 !9
         64        DO_ICALL                                                 
         65      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.6 ms | 1443 KiB | 15 Q