RE: [PHP] convert degrees to heading
| From: | Gryffyn, Trevor | Date: | Mon, 13 Sep 2004 19:22:55 +0000 |
| Subject: | RE: [PHP] convert degrees to heading | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-196557@lists.php.net to get a copy of this message | ||
Nice! I didn't know you could do that with switch. I was wondering why conditionals were left
out of PHP's switch statement, but hoped someone would prove me wrong. Thanks John! Very
helpful!
-TG
> -----Original Message-----
> From: John Holmes [mailto:holmes072000@charter.net]
> Sent: Monday, September 13, 2004 3:26 PM
> To: Gryffyn, Trevor; php
> Cc: René Fournier
> Subject: Re: [PHP] convert degrees to heading
>
>
> > I have to write a little function to convert a direction
> from degrees
> > to a compass -type heading. 0 = West. 90 = North. E.g.:
>
> Something like this... it'll account for >360 degrees, too.
> No different
> that a bunch of IF statements, though...
>
> <?php
> $dir = 378;
> switch($dir = $dir%360)
> {
> case 0 <= $dir && $dir < 90:
> echo 'northeasterly';
> break;
> case 90 <= $dir && $dir < 180:
> echo 'southeasterly';
> break;
> case 180 <= $dir && $dir < 270:
> echo 'southwesterly';
> break;
> case 270 <= $dir && $dir < 360:
> echo 'northwesterly';
> break;
> }
> ?>
>
> ---John Holmes...
>
>