Convert excel formula to php
Moderator: General Moderators
Not sure about it been between 99 - 100 ... it has =99 or =100 .. I guess as long as its a full number it will be fine under that senario. For that piece of code it would need to be
if ($rate2 >= 1 and $rate2 < 100)
if ($rate2 >= 100 and $rate2 < 200)
?
The last solution I havnt managed to get my head around to make the enitre formula to work so it includes all the if's
Cheers
if ($rate2 >= 1 and $rate2 < 100)
if ($rate2 >= 100 and $rate2 < 200)
?
The last solution I havnt managed to get my head around to make the enitre formula to work so it includes all the if's
Cheers
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
it's quite simpleat this point, it'll compare $value against 1, 100, 200, and 300. The first one it falls under is used and the loop exits. You simply add more elements to the $adjustor array. The key is the number to compare $value against and the value is the multiplier.
Code: Select all
$adjustor = array(1=>1, 100=>1.1, 200=>1.2, 300=>1.3);
foreach($adjustor as $limit => $mul)
{
if($value < $limit)
{
$value *= $mul;
break;
}
}-
Stewsburntmonkey
- Forum Commoner
- Posts: 44
- Joined: Wed Aug 24, 2005 2:09 pm
Code: Select all
$adjustor = array(1=>1, 100=>1.1, 200=>1.2, 300=>1.3, 500=>1.4);Just to reiterate, the above creates an array named adjustor and is equivalent to:
Code: Select all
$adjustor[1] = 1;
$adjustor[100] = 1.1;
$adjustor[200] = 1.2;
$adjustor[300] = 1.3;
$adjustor[500] = 1.4;Sorry this is so painfull
Something like:
That added 30% to 500 but also added 30% to 100 which should have only been 10%?
Thanks
Something like:
Code: Select all
$adjustor = array(1=>1, 100=>1.1, 200=>1.2, 300=>1.3);
$array = array_reverse($adjustor);
foreach($array as $limit => $mul)
{
if($rate2 >= $limit)
{
$rate2 *= $mul;
break;
}
}Thanks
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
[feyd@home]>php -r "var_export(array_reverse(array(1=>1, 100=>1.1, 200=>1.2, 300=>1.3)));"
array (
0 => 1.3,
1 => 1.2,
2 => 1.1,
3 => 1,
)