3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Função para ler valores de vendas de forma segura e garantir que sejam positivos function lerValor($ano) { do { $valor = readline("Digite o valor das vendas para o ano $ano: "); if ($valor <= 0) { echo "O valor deve ser positivo. Tente novamente.\n"; } } while ($valor <= 0); return $valor; } // Leitura dos valores de vendas para os anos 2020 a 2023 $vendas = []; $anos = [2020, 2021, 2022, 2023]; foreach ($anos as $ano) { $vendas[] = lerValor($ano); } // Contando quantos anos houve crescimento em relação ao anterior $crescimentos = 0; for ($i = 1; $i < count($vendas); $i++) { if ($vendas[$i] > $vendas[$i - 1]) { $crescimentos++; } } // Calculando o crescimento percentual entre 2020 e 2023 $crescimento_percentual = (($vendas[3] - $vendas[0]) / $vendas[0]) * 100; // Exibindo os resultados echo "\nNúmero de anos com crescimento em relação ao anterior: $crescimentos\n"; echo "Crescimento percentual entre 2020 e 2023: " . number_format($crescimento_percentual, 2) . "%\n"; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 14
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 14
Branch analysis from position: 24
Branch analysis from position: 14
Branch analysis from position: 20
Branch analysis from position: 10
filename:       /in/NulQq
function name:  (null)
number of ops:  43
compiled vars:  !0 = $vendas, !1 = $anos, !2 = $ano, !3 = $crescimentos, !4 = $i, !5 = $crescimento_percentual
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, <array>
   17     2      > FE_RESET_R                                       $8      !1, ->10
          3    > > FE_FETCH_R                                               $8, !2, ->10
   18     4    >   INIT_FCALL                                               'lervalor'
          5        SEND_VAR                                                 !2
          6        DO_FCALL                                      0  $10     
          7        ASSIGN_DIM                                               !0
          8        OP_DATA                                                  $10
   17     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $8
   22    11        ASSIGN                                                   !3, 0
   23    12        ASSIGN                                                   !4, 1
         13      > JMP                                                      ->21
   24    14    >   FETCH_DIM_R                                      ~13     !0, !4
         15        SUB                                              ~14     !4, 1
         16        FETCH_DIM_R                                      ~15     !0, ~14
         17        IS_SMALLER                                               ~15, ~13
         18      > JMPZ                                                     ~16, ->20
   25    19    >   PRE_INC                                                  !3
   23    20    >   PRE_INC                                                  !4
         21    >   COUNT                                            ~19     !0
         22        IS_SMALLER                                               !4, ~19
         23      > JMPNZ                                                    ~20, ->14
   30    24    >   FETCH_DIM_R                                      ~21     !0, 3
         25        FETCH_DIM_R                                      ~22     !0, 0
         26        SUB                                              ~23     ~21, ~22
         27        FETCH_DIM_R                                      ~24     !0, 0
         28        DIV                                              ~25     ~23, ~24
         29        MUL                                              ~26     ~25, 100
         30        ASSIGN                                                   !5, ~26
   33    31        ROPE_INIT                                     3  ~29     '%0AN%C3%BAmero+de+anos+com+crescimento+em+rela%C3%A7%C3%A3o+ao+anterior%3A+'
         32        ROPE_ADD                                      1  ~29     ~29, !3
         33        ROPE_END                                      2  ~28     ~29, '%0A'
         34        ECHO                                                     ~28
   34    35        INIT_FCALL                                               'number_format'
         36        SEND_VAR                                                 !5
         37        SEND_VAL                                                 2
         38        DO_ICALL                                         $31     
         39        CONCAT                                           ~32     'Crescimento+percentual+entre+2020+e+2023%3A+', $31
         40        CONCAT                                           ~33     ~32, '%25%0A'
         41        ECHO                                                     ~33
   35    42      > RETURN                                                   1

Function lervalor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 1
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 1
Branch analysis from position: 11
filename:       /in/NulQq
function name:  lerValor
number of ops:  15
compiled vars:  !0 = $ano, !1 = $valor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1    >   INIT_FCALL_BY_NAME                                       'readline'
          2        ROPE_INIT                                     3  ~3      'Digite+o+valor+das+vendas+para+o+ano+'
          3        ROPE_ADD                                      1  ~3      ~3, !0
          4        ROPE_END                                      2  ~2      ~3, '%3A+'
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !1, $5
    6     8        IS_SMALLER_OR_EQUAL                                      !1, 0
          9      > JMPZ                                                     ~7, ->11
    7    10    >   ECHO                                                     'O+valor+deve+ser+positivo.+Tente+novamente.%0A'
    9    11    >   IS_SMALLER_OR_EQUAL                                      !1, 0
         12      > JMPNZ                                                    ~8, ->1
   11    13    > > RETURN                                                   !1
   12    14*     > RETURN                                                   null

End of function lervalor

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.76 ms | 960 KiB | 15 Q