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.

VB6 to PHP ... temptation while it is easy ... do you know VB6 or PHP ?

Member Avatar for diafol

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?

commented: Thanks, you're the man! +7

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.;)

Member Avatar for diafol

> 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! :)

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!:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.