Jump to content

Is there a way to condense down these variables?


dreampho

Recommended Posts

Hi.

 

Is there a way to condense down these variables? I am not sure if you can do something like:

 

$deposit = substr($deposit_before, 1); str_replace(",", "", $deposit_before);

 

 $price = $this->EE->TMPL->fetch_param('price');

 $deposit_before = $this->EE->TMPL->fetch_param('deposit');
 $deposit_after = substr($deposit_before, 1);
 $deposit = str_replace(",", "", $deposit_after);

 $query = $this->EE->db->query("SELECT * FROM exp_currency");

 $usd = $query->row('usd');
 $eur = $query->row('eur');
 $gbp = $query->row('gbp');

 /* Price */
 $usd_price_convert = $price * $usd;
 $usd_price = number_format($usd_price_convert, 2, '.', '');
 $eur_price_convert = $price * $eur;
 $eur_price = number_format($eur_price_convert, 2, '.', '');
 $gbp_price_convert = $price * $gbp;
 $gbp_price = number_format($gbp_price_convert, 2, '.', '');

 /* Deposit */
 $usd_deposit_convert = $deposit * $usd;
 $usd_deposit = number_format($usd_deposit_convert, 2, '.', '');
 $eur_deposit_convert = $deposit * $eur;
 $eur_deposit = number_format($eur_deposit_convert, 2, '.', '');
 $gbp_deposit_convert = $deposit * $gbp;
 $gbp_deposit = number_format($gbp_deposit_convert, 2, '.', '');

You could just re-use the same variable name as your temporary variables:

$deposit = $this->EE->TMPL->fetch_param('deposit');
$deposit = substr($deposit, 1);
$deposit = str_replace(",", "", $deposit);

 

You could also just pass the return value of one function straight into the other.

$deposit = $this->EE->TMPL->fetch_param('deposit');
$deposit = str_replace(",", "", substr($deposit, 1));

 

Thank you. I didnt realise you could do that.

 

Could I do something similar with this:

 

  	 $usd_price_convert = $price * $usd;
  	 $usd_price = number_format($usd_price_convert, 2, '.', '');

 

Perhaps something like:

 

  	 $usd_price = ($price * $usd, number_format($usd_price, 2, '.', ''));

       $usd_price = ($price * $usd, number_format($usd_price, 2, '.', ''));

 

It would be like this:

$usd_price = number_format($price * $usd, 2, '.', '');

 

You put the calculation in place of where the variable was.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.