3v4l.org

run code in 300+ PHP versions simultaneously
<?php function totaal($bedragen, $btw = false) { $ftotaal = array_sum($bedragen); if($btw) { $ftotaal *= 1.19; } return number_format($ftotaal, 2); } $bedragen = array(5.45, 9.95, 34.95); echo 'totaal excl. btw: '.totaal($bedragen).'<br>'; echo 'totaal excl. btw: '.totaal($bedragen), true.'<br>'; // 15-16 kunnen we ook zo schrijven: echo 'totaal excl. btw: '; echo totaal($bedragen); echo '<br>'; echo 'totaal excl. btw: '; echo totaal($bedragen); echo true; // het zelfde als echo '1'; echo '<br>'; ?> <?php // Functie definiƫren function calcTotaal($aBedragen, $bBtw = false) { // Totaal van prijzen berekenen $fTotaal = array_sum($aBedragen); // Controleren of BTW berekend moet worden if($bBtw) { // Het totaal * 1.19 (19% BTW) $fTotaal *= 1.19; } // Geef het berekende totaal terug return number_format($fTotaal, 2); } // Functie aanroepen $aBedragen = array(5.45, 9.95, 34.95); echo 'Totaal excl. BTW: '.calcTotaal($aBedragen).'<br />'; echo 'Totaal incl. BTW: '.calcTotaal($aBedragen, true).'<br />'; // 48-49 kunnen we ook zo schrijven: echo 'Totaal excl. BTW: '; echo calcTotaal($aBedragen); echo '<br />'; echo 'Totaal incl. BTW: '; echo calcTotaal($aBedragen, true); echo '<br />'; ?>
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
totaal excl. btw: 50.35<br>totaal excl. btw: 50.351<br>totaal excl. btw: 50.35<br>totaal excl. btw: 50.351<br> Totaal excl. BTW: 50.35<br />Totaal incl. BTW: 59.92<br />Totaal excl. BTW: 50.35<br />Totaal incl. BTW: 59.92<br />

preferences:
228 ms | 406 KiB | 385 Q