Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #1934 > unrolled thread
| Started by | geoff@invalid.invalid |
|---|---|
| First post | 2011-05-30 15:52 +0100 |
| Last post | 2011-05-30 16:14 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.php
a more elegant way? geoff@invalid.invalid - 2011-05-30 15:52 +0100
Re: a more elegant way? dougatmilmacdotcom@example.com (Doug Miller) - 2011-05-30 15:03 +0000
Re: a more elegant way? geoff@invalid.invalid - 2011-05-30 16:14 +0100
| From | geoff@invalid.invalid |
|---|---|
| Date | 2011-05-30 15:52 +0100 |
| Subject | a more elegant way? |
| Message-ID | <0mb7u694aqigfmbdi5ic943mv189ptsh7f@4ax.com> |
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
[toc] | [next] | [standalone]
| From | dougatmilmacdotcom@example.com (Doug Miller) |
|---|---|
| Date | 2011-05-30 15:03 +0000 |
| Message-ID | <is0bl4$iu3$2@dont-email.me> |
| In reply to | #1934 |
In article <0mb7u694aqigfmbdi5ic943mv189ptsh7f@4ax.com>, geoff@invalid.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;
}
[toc] | [prev] | [next] | [standalone]
| From | geoff@invalid.invalid |
|---|---|
| Date | 2011-05-30 16:14 +0100 |
| Message-ID | <r0d7u610qb0lg231l25p915aoeofcascr8@4ax.com> |
| In reply to | #1938 |
On Mon, 30 May 2011 15:03:57 GMT, dougatmilmacdotcom@example.com (Doug
Miller) wrote:
>In article <0mb7u694aqigfmbdi5ic943mv189ptsh7f@4ax.com>, geoff@invalid.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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web