Skip to content

Instantly share code, notes, and snippets.

@iansvo
Created January 18, 2016 18:39
Show Gist options
  • Save iansvo/e09c29e80190a37334a1 to your computer and use it in GitHub Desktop.
Save iansvo/e09c29e80190a37334a1 to your computer and use it in GitHub Desktop.
Simple PHP function that turns directional degrees into cardinal directions
// @param $int - degree integer value
function get_dir_from_deg($int)
{
$calc = (int) ($int / 22.5 ) + .5;
$dirs = ["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"];
$index = $calc % 16;
return $dirs[$index];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment