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:[EMAIL PROTECTED] > 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... > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php