Re: range if/else...broken
| From: | Lars Torben Wilson | Date: | Thu, 31 Aug 2000 03:20:34 +0000 |
| Subject: | Re: range if/else...broken | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14502@lists.php.net to get a copy of this message | ||
John Corry writes:
>
> //this returns the integer, 242.
> $day = (date("z"));
>
>
> // this *should* return a value for $price that comes from the field
> 'lo_price'
> // but it doesn't...why not?
>
> if ($day == range(105,349)) {
> $price = $myrow['lo_price'];
> } else {
> $price =$myrow['hi_price'];
> }
>
>
> Thank you, I'm having a blast learning this stuff...
> John Corry
That's a lot like the Pascal syntax for something like
this. Unfortunately, range() returns an array in PHP, which means
you'd have to search the array to find out whether your variable was
between those two numbers, which involves first creating an array with
range(), and then using something like in_array() to search it. You'll
save some overhead by doing something like this instead:
//this returns the integer, 242.
$day = (date("z"));
// this *should* return a value for $price that comes from the field 'lo_price'
// but it doesn't...why not?
if (($day >= 105) && ($day <= 349)) {
$price = $myrow['lo_price'];
} else {
$price =$myrow['hi_price'];
}
Cheers,
Torben
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+