コード例 #1
0
ファイル: clausuras_ambito.php プロジェクト: ezrra/PHP
     * @return [type]           [description]
     */
    public function obtenercantidad($producto)
    {
        return isset($this->productos[$producto]) ? $this->productos[$producto] : FALSE;
    }
    /**
     * [obtenerTotal función]
     * @param  [type] $impuesto [description]
     * @return [type]           [description]
     */
    public function obtenerTotal($impuesto)
    {
        $total = 0.0;
        $llamadaDeRetorno = function ($cantidad, $producto) use($impuesto, &$total) {
            $precioUnitario = constant(__CLASS__ . "::PRECIO_" . strtoupper($producto));
            $total += $precioUnitario * $cantidad * ($impuesto + 1.0);
        };
        array_walk($this->productos, $llamadaDeRetorno);
        return round($total, 2);
    }
}
/**
 * Ejecutando la clase
 */
$mi_carro = new Carro();
// Añadir
$mi_carro->agregar('mantequilla', 1);
$mi_carro->agregar('leche', 3);
$mi_carro->agregar('huevos', 6);
print $mi_carro->obtenerTotal(0.05) . "\n";