dreampho Posted January 23, 2013 Share Posted January 23, 2013 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, '.', ''); Quote Link to comment https://forums.phpfreaks.com/topic/273546-is-there-a-way-to-condense-down-these-variables/ Share on other sites More sharing options...
kicken Posted January 23, 2013 Share Posted January 23, 2013 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)); Quote Link to comment https://forums.phpfreaks.com/topic/273546-is-there-a-way-to-condense-down-these-variables/#findComment-1407751 Share on other sites More sharing options...
dreampho Posted January 23, 2013 Author Share Posted January 23, 2013 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, '.', '')); Quote Link to comment https://forums.phpfreaks.com/topic/273546-is-there-a-way-to-condense-down-these-variables/#findComment-1407755 Share on other sites More sharing options...
kicken Posted January 23, 2013 Share Posted January 23, 2013 $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. Quote Link to comment https://forums.phpfreaks.com/topic/273546-is-there-a-way-to-condense-down-these-variables/#findComment-1407761 Share on other sites More sharing options...
dreampho Posted January 24, 2013 Author Share Posted January 24, 2013 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/273546-is-there-a-way-to-condense-down-these-variables/#findComment-1407874 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.