FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » a more elegant way?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
a more elegant way? [message #174274] Mon, 30 May 2011 14:52 Go to next message
geoff is currently offline  geoff
Messages: 8
Registered: April 2011
Karma: 0
Junior Member
Hello

No doubt there is a better way of expressing this?!

Pointers please ...

if ($value > 0 && $value < 11) {
$section_addressed = '1';
}
if ($value > 10 && $value < 21) {
$section_addressed = '2';
}
if ($value > 20 && $value < 31) {
$section_addressed = '3';
}
if ($value > 30 && $value < 41) {
$section_addressed = '4';
}
if ($value > 40 && $value < 51) {
$section_addressed = '5';
}
if ($value > 50 && $value < 61) {
$section_addressed = '6';
}
if ($value > 60 && $value < 71) {
$section_addressed = '7';
}
if ($value > 70 && $value < 81) {
$section_addressed = '8';
}
if ($value > 80 && $value < 91) {
$section_addressed = '9';
}
if ($value > 90 && $value < 101) {
$section_addressed = '10';
}
if ($value > 100 && $value < 111) {
$section_addressed = '11';
}
if ($value > 110 && $value < 121) {
$section_addressed = '12';
}

Cheers

Geoff
Re: a more elegant way? [message #174276 is a reply to message #174274] Mon, 30 May 2011 15:03 Go to previous messageGo to next message
dougatmilmacdotcom is currently offline  dougatmilmacdotcom
Messages: 24
Registered: May 2011
Karma: 0
Junior Member
In article <0mb7u694aqigfmbdi5ic943mv189ptsh7f(at)4ax(dot)com>, geoff(at)invalid(dot)invalid wrote:
> Hello

Please disregard my previous post; I hit send a bit too quickly, before
reviewing what I'd written.
>
> No doubt there is a better way of expressing this?!

Yes, there is.
>
> Pointers please ...
>
> if ($value > 0 && $value < 11) {
> $section_addressed = '1';
> }
> if ($value > 10 && $value < 21) {
> $section_addressed = '2';
> }
> if ($value > 20 && $value < 31) {
> $section_addressed = '3';
> }
[...]
> if ($value > 110 && $value < 121) {
> $section_addressed = '12';
> }

if ($value > 0 && $value < 121) {
$section_addressed = floor (($value - 1) / 10) + 1;
}
Re: a more elegant way? [message #174277 is a reply to message #174276] Mon, 30 May 2011 15:14 Go to previous message
geoff is currently offline  geoff
Messages: 8
Registered: April 2011
Karma: 0
Junior Member
On Mon, 30 May 2011 15:03:57 GMT, dougatmilmacdotcom(at)example(dot)com (Doug
Miller) wrote:

> In article <0mb7u694aqigfmbdi5ic943mv189ptsh7f(at)4ax(dot)com>, geoff(at)invalid(dot)invalid wrote:
>> Hello
>
> Please disregard my previous post; I hit send a bit too quickly, before
> reviewing what I'd written.
>>
>> No doubt there is a better way of expressing this?!
>
> Yes, there is.
>>
>> Pointers please ...
>>
>> if ($value > 0 && $value < 11) {
>> $section_addressed = '1';
>> }
>> if ($value > 10 && $value < 21) {
>> $section_addressed = '2';
>> }
>> if ($value > 20 && $value < 31) {
>> $section_addressed = '3';
>> }
> [...]
>> if ($value > 110 && $value < 121) {
>> $section_addressed = '12';
>> }
>
> if ($value > 0 && $value < 121) {
> $section_addressed = floor (($value - 1) / 10) + 1;
> }

Thanks Doug!

Cheers

Geoff
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: database access
Next Topic: Storing parsed XML-elements as blobs
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 29 13:59:41 GMT 2024

Total time taken to generate the page: 0.02102 seconds