Skip to content

Instantly share code, notes, and snippets.

@codatory
Created April 10, 2009 16:10
Show Gist options
  • Save codatory/93140 to your computer and use it in GitHub Desktop.
Save codatory/93140 to your computer and use it in GitHub Desktop.
PHP Function for calculating weight watcher's point values.
<?php
function calculate ($calories, $fiber, $fat) {
$points_from_fat = $fat / 12;
if ($fiber = 0) {
$fiber_caloric_reduction = 0;
} elseif ($fiber < 4) {
$fiber_caloric_reduction = $fiber * 10;
} elseif ($fiber > 4) {
$fiber_caloric_reduction = 40;
}
if ($calories < $fiber_caloric_reduction) {
$calories = 0;
} elseif ($calories > $fiber_caloric_reduction) {
$calories = $calories - $fiber_caloric_reduction;
}
$result = ($calories / 50) + $points_from_fat;
$result = round($result);
return $result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment