Hi Trevor,
Very nice solution, Dave. I like simple, elegant and effective
solutions like this. I was wracking my brain yesterday to come up with
something like this, but my brain wasn't working. Hah. Good job!
Thanks for the compliments - my head is now a bit bigger :-)
I thought 0
Hi,
Alternatively, try :-
$Compass = array('West', 'North Westerly', 'North', 'North Easterly',
'East', 'South Easterly', 'South',
'South Westerly');
print $Compass[round($Degrees / 45)] . \n;
This can be expanded easily by adding 'North North
Hi,
Alternatively, try :-
$Compass = array('West', 'North Westerly', 'North', 'North Easterly',
'East', 'South Easterly', 'South',
'South Westerly');
print $Compass[round($Degrees / 45)] . \n;
This can be expanded easily by adding 'North
: 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
Message-
From: Dave Restall - System Administrator,,,
[mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 14, 2004 4:14 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; Gryffyn, Trevor
Subject: Re: [PHP] convert degrees to heading
Hi,
Alternatively, try :-
$Compass = array('West
The cleanest looking multiple if scenario is to use a Switch statement.
Unfortunately I don't believe PHP's switch will do varied conditions, only equality
statements:
$j = 5;
switch ($j) {
case 6:
echo first;
break;
case 6:
echo second;
break;
case 5:
echo third;
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 =
, 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
[snip]
The cleanest looking multiple if scenario is to use a Switch statement.
Unfortunately I don't believe PHP's switch will do varied conditions, only equality
statements:
$j = 5;
switch ($j) {
case 6:
echo first;
break;
case 6:
echo second;
break;
case 5:
echo
On Tuesday 14 September 2004 02:18, Gryffyn, Trevor wrote:
In some other languages, you could put your range of values in the case
statements, but not PHP I guess.
switch(true) {
case (expr1) : //do something;
break;
case (expr2) : //do something else;
10 matches
Mail list logo