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 />'; ?>

preferences:
68.69 ms | 402 KiB | 5 Q