0

I'm not sure how to write this in php, so any help will be appreciated -

In vb6, I would have had a function similar to this code -

Function GetReserve()
Dim xAmount As Integer, xValue As Integer

Select Case xAmount 'Where xAmount is an Integer

Case Is = 0 And < 99
xValue = 5

Case Is = 100 And < 199
xValue = 10

End Select

How can I rewrite AND use this in php, please.

3
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by AndreRet
1

Andre - seeing as it's you...:)

function GetReserve($xAmount){
 
  switch(true){
    case ($xAmount >= 0 && $xAmount < 100):
      $xValue = 5;
    break;
    case ($xAmount >= 100 && $xAmount <= 199):
      $xValue = 10;
    break;
    default:
      $xValue = 0; //if not between 0 and 199!
    break;
  }
  return $xValue;
}

I may be wrong, but your code showed <99 and then 100+, which means 99 would not be included at all. Was this intentional? I've changed it to 0-99,100-199. Again, your second case would not include 199 nor 200.

Ok, example use:

$int = 78;
$reserve = GetReserve($int);

Not tested. Range testing with switch in php is a pain. I usually test it agianst 'true'. If somebody has a better was to do range testing in switch, please let me know.

Ok, how about that bottle of Castle?

Edited by diafol: n/a

Votes + Comments
Thanks, you're the man!
0

Andre - seeing as it's you

You're the man, thanks.

Code seems to work fine as well, some kudos fur ya':)

which means 99 would not be included at all. Was this intentional?

No, dropped a few brain cells here, should have been equal or less to 99 etc.

Ok, how about that bottle of Castle?

Oh yah, I'll have two on you tonight, that ok.;) You know you're beer!!!, but then again, S.A. Breweries is producing half the worlds beer anyway.;)

Edited by AndreRet: n/a

0

> but then again, S.A. Breweries is producing half the worlds beer anyway.

Now you're talking. If you come over to Cardiff for an international I'll buy you a pint of Brains S.A. (known locally as Skull Attack). I have to warn you it's an acquired taste. One that I kept on trying to acquire for 20 years. I'm a glutton for punishment, or perhaps just a glutton! :)

0

LOL, I think we'll get along very well then, or at least the parts we can remember should seem that we did.;)

If that counts as gluttony, I'm a leading expert in the field, also 20 years of acquiring a taste for some alcohol beverages, still trying, probably will for some time!:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.