sobre funciones

From: Date: Fri, 07 Dec 2007 15:59:31 +0000
Subject: sobre funciones
Groups: php.general.es 
Request: Send a blank email to general-es+get-61929@lists.php.net to get a copy of this message
Hola, soy bastante nuevo en PHP. El caso es que tengo el siguiente codigo en el que una variable usa unos valores para hacer unos calculos pero estos no se reflejan fuera de la funcion aunque use return. Que esta fallando? un saludo y gracias <?php function my_product($product, $price, $shipping){ $total_price += $price; $total_tax += $price * $tax; $total_shipping += $shipping * $price; $grand_total = ($total_price + $total_tax + $total_shipping); echo "<li>".$product.": $".$price."</li>"; echo "<li> a ver si sale...".$grand_total."</li>"; } $tax = 0.08; $total_price = 0; $total_tax = 0; $total_shipping = 0; $grand_total = 0; ?> <ul> <?php my_product("Candle Holder",10,0); my_product("LED",20,2); ?> </ul> Subtotal: $<? echo number_format($total_price, 2); ?><br> Tax: $<? echo number_format($total_tax,2); ?><br> Shipping: $<? echo number_format($total_shipping, 2); ?><br> <b>Total: $<? echo number_format($grand_total, 2); ?><br><b>

« previous php.general.es (#61929) next »