3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Verifica se a função já foi declarada if (!function_exists('lerVendas')) { // Função para garantir que o valor digitado seja positivo function lerVendas($ano) { do { echo "Digite o valor das vendas de $ano: "; $venda = trim(fgets(STDIN)); if ($venda <= 0) { echo "O valor deve ser positivo. Tente novamente.\n"; } } while ($venda <= 0); return $venda; } } // Leitura dos valores de vendas para os anos 2020, 2021, 2022 e 2023 $vendas = []; $anos = [2020, 2021, 2022, 2023]; foreach ($anos as $ano) { $vendas[$ano] = lerVendas($ano); } // Verificação de quantos anos tiveram crescimento em relação ao ano anterior $crescimentoAnos = 0; for ($i = 1; $i < count($anos); $i++) { if ($vendas[$anos[$i]] > $vendas[$anos[$i - 1]]) { $crescimentoAnos++; } } // Cálculo do crescimento percentual entre 2020 e 2023 $crescimentoPercentual = (($vendas[2023] - $vendas[2020]) / $vendas[2020]) * 100; // Saídas echo "\nO número de anos em que as vendas cresceram em relação ao ano anterior: $crescimentoAnos\n"; echo "O crescimento percentual entre 2020 e 2023 foi de " . number_format($crescimentoPercentual, 2) . "%\n"; ?> <?php // Verifica se a função já foi declarada if (!function_exists('lerVendas')) { // Função para garantir que o valor digitado seja positivo function lerVendas($ano) { do { echo "Digite o valor das vendas de $ano: "; $venda = trim(fgets(STDIN)); if ($venda <= 0) { echo "O valor deve ser positivo. Tente novamente.\n"; } } while ($venda <= 0); return $venda; } } // Leitura dos valores de vendas para os anos 2020, 2021, 2022 e 2023 $vendas = []; $anos = [2020, 2021, 2022, 2023]; foreach ($anos as $ano) { $vendas[$ano] = lerVendas($ano); } // Verificação de quantos anos tiveram crescimento em relação ao ano anterior $crescimentoAnos = 0; for ($i = 1; $i < count($anos); $i++) { if ($vendas[$anos[$i]] > $vendas[$anos[$i - 1]]) { $crescimentoAnos++; } } // Cálculo do crescimento percentual entre 2020 e 2023 $crescimentoPercentual = (($vendas[2023] - $vendas[2020]) / $vendas[2020]) * 100; // Saídas echo "\nO número de anos em que as vendas cresceram em relação ao ano anterior: $crescimentoAnos\n"; echo "O crescimento percentual entre 2020 e 2023 foi de " . number_format($crescimentoPercentual, 2) . "%\n"; ?>

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 20
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 56
Branch analysis from position: 55
2 jumps found. (Code = 77) Position 1 = 59, Position 2 = 66
Branch analysis from position: 59
2 jumps found. (Code = 78) Position 1 = 60, Position 2 = 66
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 70
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 78
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 70
Branch analysis from position: 82
Branch analysis from position: 70
Branch analysis from position: 78
Branch analysis from position: 66
Branch analysis from position: 56
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 20
Branch analysis from position: 32
Branch analysis from position: 20
Branch analysis from position: 28
Branch analysis from position: 16
Branch analysis from position: 6
filename:       /in/rEjOs
function name:  (null)
number of ops:  101
compiled vars:  !0 = $vendas, !1 = $anos, !2 = $ano, !3 = $crescimentoAnos, !4 = $i, !5 = $crescimentoPercentual
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'lerVendas'
          2        DO_ICALL                                         $6      
          3        BOOL_NOT                                         ~7      $6
          4      > JMPZ                                                     ~7, ->6
    5     5    >   DECLARE_FUNCTION                                         'lervendas'
   18     6    >   ASSIGN                                                   !0, <array>
   19     7        ASSIGN                                                   !1, <array>
   21     8      > FE_RESET_R                                       $10     !1, ->16
          9    > > FE_FETCH_R                                               $10, !2, ->16
   22    10    >   INIT_FCALL_BY_NAME                                       'lerVendas'
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $12     
         13        ASSIGN_DIM                                               !0, !2
         14        OP_DATA                                                  $12
   21    15      > JMP                                                      ->9
         16    >   FE_FREE                                                  $10
   26    17        ASSIGN                                                   !3, 0
   28    18        ASSIGN                                                   !4, 1
         19      > JMP                                                      ->29
   29    20    >   FETCH_DIM_R                                      ~15     !1, !4
         21        FETCH_DIM_R                                      ~16     !0, ~15
         22        SUB                                              ~17     !4, 1
         23        FETCH_DIM_R                                      ~18     !1, ~17
         24        FETCH_DIM_R                                      ~19     !0, ~18
         25        IS_SMALLER                                               ~19, ~16
         26      > JMPZ                                                     ~20, ->28
   30    27    >   PRE_INC                                                  !3
   28    28    >   PRE_INC                                                  !4
         29    >   COUNT                                            ~23     !1
         30        IS_SMALLER                                               !4, ~23
         31      > JMPNZ                                                    ~24, ->20
   35    32    >   FETCH_DIM_R                                      ~25     !0, 2023
         33        FETCH_DIM_R                                      ~26     !0, 2020
         34        SUB                                              ~27     ~25, ~26
         35        FETCH_DIM_R                                      ~28     !0, 2020
         36        DIV                                              ~29     ~27, ~28
         37        MUL                                              ~30     ~29, 100
         38        ASSIGN                                                   !5, ~30
   38    39        ROPE_INIT                                     3  ~33     '%0AO+n%C3%BAmero+de+anos+em+que+as+vendas+cresceram+em+rela%C3%A7%C3%A3o+ao+ano+anterior%3A+'
         40        ROPE_ADD                                      1  ~33     ~33, !3
         41        ROPE_END                                      2  ~32     ~33, '%0A'
         42        ECHO                                                     ~32
   39    43        INIT_FCALL                                               'number_format'
         44        SEND_VAR                                                 !5
         45        SEND_VAL                                                 2
         46        DO_ICALL                                         $35     
         47        CONCAT                                           ~36     'O+crescimento+percentual+entre+2020+e+2023+foi+de+', $35
         48        CONCAT                                           ~37     ~36, '%25%0A'
         49        ECHO                                                     ~37
   43    50        INIT_FCALL                                               'function_exists'
         51        SEND_VAL                                                 'lerVendas'
         52        DO_ICALL                                         $38     
         53        BOOL_NOT                                         ~39     $38
         54      > JMPZ                                                     ~39, ->56
   45    55    >   DECLARE_FUNCTION                                         'lervendas'
   58    56    >   ASSIGN                                                   !0, <array>
   59    57        ASSIGN                                                   !1, <array>
   61    58      > FE_RESET_R                                       $42     !1, ->66
         59    > > FE_FETCH_R                                               $42, !2, ->66
   62    60    >   INIT_FCALL_BY_NAME                                       'lerVendas'
         61        SEND_VAR_EX                                              !2
         62        DO_FCALL                                      0  $44     
         63        ASSIGN_DIM                                               !0, !2
         64        OP_DATA                                                  $44
   61    65      > JMP                                                      ->59
         66    >   FE_FREE                                                  $42
   66    67        ASSIGN                                                   !3, 0
   68    68        ASSIGN                                                   !4, 1
         69      > JMP                                                      ->79
   69    70    >   FETCH_DIM_R                                      ~47     !1, !4
         71        FETCH_DIM_R                                      ~48     !0, ~47
         72        SUB                                              ~49     !4, 1
         73        FETCH_DIM_R                                      ~50     !1, ~49
         74        FETCH_DIM_R                                      ~51     !0, ~50
         75        IS_SMALLER                                               ~51, ~48
         76      > JMPZ                                                     ~52, ->78
   70    77    >   PRE_INC                                                  !3
   68    78    >   PRE_INC                                                  !4
         79    >   COUNT                                            ~55     !1
         80        IS_SMALLER                                               !4, ~55
         81      > JMPNZ                                                    ~56, ->70
   75    82    >   FETCH_DIM_R                                      ~57     !0, 2023
         83        FETCH_DIM_R                                      ~58     !0, 2020
         84        SUB                                              ~59     ~57, ~58
         85        FETCH_DIM_R                                      ~60     !0, 2020
         86        DIV                                              ~61     ~59, ~60
         87        MUL                                              ~62     ~61, 100
         88        ASSIGN                                                   !5, ~62
   78    89        ROPE_INIT                                     3  ~65     '%0AO+n%C3%BAmero+de+anos+em+que+as+vendas+cresceram+em+rela%C3%A7%C3%A3o+ao+ano+anterior%3A+'
         90        ROPE_ADD                                      1  ~65     ~65, !3
         91        ROPE_END                                      2  ~64     ~65, '%0A'
         92        ECHO                                                     ~64
   79    93        INIT_FCALL                                               'number_format'
         94        SEND_VAR                                                 !5
         95        SEND_VAL                                                 2
         96        DO_ICALL                                         $67     
         97        CONCAT                                           ~68     'O+crescimento+percentual+entre+2020+e+2023+foi+de+', $67
         98        CONCAT                                           ~69     ~68, '%25%0A'
         99        ECHO                                                     ~69
   80   100      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 1
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 1
Branch analysis from position: 16
filename:       /in/rEjOs
function name:  lerVendas
number of ops:  20
compiled vars:  !0 = $ano, !1 = $venda
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1    >   ROPE_INIT                                     3  ~3      'Digite+o+valor+das+vendas+de+'
          2        ROPE_ADD                                      1  ~3      ~3, !0
          3        ROPE_END                                      2  ~2      ~3, '%3A+'
          4        ECHO                                                     ~2
    8     5        INIT_FCALL                                               'trim'
          6        INIT_FCALL                                               'fgets'
          7        FETCH_CONSTANT                                   ~5      'STDIN'
          8        SEND_VAL                                                 ~5
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !1, $7
    9    13        IS_SMALLER_OR_EQUAL                                      !1, 0
         14      > JMPZ                                                     ~9, ->16
   10    15    >   ECHO                                                     'O+valor+deve+ser+positivo.+Tente+novamente.%0A'
   12    16    >   IS_SMALLER_OR_EQUAL                                      !1, 0
         17      > JMPNZ                                                    ~10, ->1
   13    18    > > RETURN                                                   !1
   14    19*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 1
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 1
Branch analysis from position: 16
filename:       /in/rEjOs
function name:  lerVendas
number of ops:  20
compiled vars:  !0 = $ano, !1 = $venda
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1    >   ROPE_INIT                                     3  ~3      'Digite+o+valor+das+vendas+de+'
          2        ROPE_ADD                                      1  ~3      ~3, !0
          3        ROPE_END                                      2  ~2      ~3, '%3A+'
          4        ECHO                                                     ~2
   48     5        INIT_FCALL                                               'trim'
          6        INIT_FCALL                                               'fgets'
          7        FETCH_CONSTANT                                   ~5      'STDIN'
          8        SEND_VAL                                                 ~5
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !1, $7
   49    13        IS_SMALLER_OR_EQUAL                                      !1, 0
         14      > JMPZ                                                     ~9, ->16
   50    15    >   ECHO                                                     'O+valor+deve+ser+positivo.+Tente+novamente.%0A'
   52    16    >   IS_SMALLER_OR_EQUAL                                      !1, 0
         17      > JMPNZ                                                    ~10, ->1
   53    18    > > RETURN                                                   !1
   54    19*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.96 ms | 969 KiB | 17 Q