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"; ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.20.0130.00619.73
8.4.10.0080.00019.61
8.3.160.0150.00420.63
8.3.150.0060.01317.38
8.3.140.0060.00317.35
8.3.130.0040.00418.65
8.3.120.0070.00416.73
8.3.110.0300.01116.23
8.3.100.0430.00316.36
8.3.90.0400.00716.50
8.3.80.0360.01216.61
8.3.70.0340.01016.38
8.3.60.0420.00716.50
8.3.50.0320.01316.38
8.3.40.0320.00617.50
8.3.30.0350.00717.38
8.3.20.0330.01317.38
8.3.10.0300.01017.50
8.3.00.0120.00917.63
8.2.270.0130.00616.88
8.2.260.0140.00417.41
8.2.250.0030.00618.78
8.2.240.0100.00018.75
8.2.230.0260.00616.37
8.2.220.0260.00616.63
8.2.210.0320.00416.59
8.2.200.0270.01316.63
8.2.190.0300.01516.13
8.2.180.0290.00316.66
8.2.170.0260.01117.88
8.2.160.0250.00417.61
8.2.150.0140.00717.50
8.2.140.0300.01317.50
8.2.130.0290.00417.38
8.2.120.0330.00317.38
8.2.110.0370.00717.38
8.2.100.0250.01717.38
8.2.90.0400.00317.38
8.2.80.0330.01017.48
8.2.70.0400.00417.25
8.2.60.0380.00917.13
8.2.50.0360.00717.38
8.2.40.0330.00817.50
8.2.30.0300.01317.38
8.2.20.0370.00617.38
8.2.10.0280.00617.13
8.2.00.0250.01417.25
8.1.310.0040.00416.80
8.1.300.0090.00019.93
8.1.290.0350.00616.13
8.1.280.0410.00016.13
8.1.270.0360.00617.09
8.1.260.0280.00917.23
8.1.250.0280.01217.00
8.1.240.0320.00717.23
8.1.230.0270.00817.13
8.1.220.0350.00017.38
8.1.210.0320.00317.10
8.1.200.0300.00817.22
8.1.190.0350.00417.11
8.1.180.0220.01617.13
8.1.170.0310.00816.97
8.1.160.0380.00317.00
8.1.150.0420.00317.13
8.1.140.0520.01017.00
8.1.130.0350.00617.10
8.1.120.0350.00417.35
8.1.110.0300.01017.34
8.1.100.0410.00317.25
8.1.90.0360.00016.98
8.1.80.0240.01517.00
8.1.70.0320.00417.35
8.1.60.0300.01117.38
8.1.50.0310.01017.25
8.1.40.0340.00617.13
8.1.30.0300.01017.35
8.1.20.0330.00417.35
8.1.10.0310.00817.22
8.1.00.0250.00717.00

preferences:
36.32 ms | 403 KiB | 5 Q