Visualizzazione dei risultati da 1 a 2 su 2

Discussione: solo con le funzioni

  1. #1

    solo con le funzioni

    Qualcuno mi può aiutare?
    Come posso raccogliere in una funzione il codice ripetitivo e portarlo fuori dal programma qui sotto?

    Checkout

    Below is a summary of the products you wish to purchase, along with totals:
    <?php

    #tax rate is constant
    $tax = 0.08;
    ?>
    <ul>

    <?php
    function CH($price, $tax, $shipping){
    $total_price += $price;
    $total_tax += $tax * $price;
    $total_shipping += $shipping * $price;
    $total= ($total_price + $total_tax + $total_shipping);
    $product = "Candle Holder";
    $price = 12.95;
    $shipping = 0;
    echo "[*]" .$product.": $".$price."
    ";
    return $total;
    }
    $CH = CH(12.95, 0.08, 0); //
    echo "Sub-totals = $" .$CH."
    ";
    ?>

    <?php
    function CT($price, $tax, $shipping){
    $total_price += $price;
    $total_tax += $tax * $price;
    $total_shipping += $shipping * $price;
    $total = ($total_price + $total_tax + $total_shipping);
    $product = "Coffee Table";
    $price = 99.50;
    $shipping = 0.01;
    echo "[*]" .$product.": $".$price."
    ";
    return $total;
    }
    $CT = CT(99.50, 0.08, 0.1); //
    echo "Sub-total = $" .$CT."
    ";
    ?>

    <?php
    $grand_total = ($CH + $CT);
    ?>
    [B]TOTAL : $<? echo number_format($grand_total, 2);?>[B]

  2. #2

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.