Using the math functions

How to calculate the distance between two points

<?php
  $x1 = 5; $y1 = 4;
  $x2 = 2; $y2 = 8;
  $distance = sqrt(pow($x1 - $x2, 2) + pow($y1 - $y2, 2)); // 5
?>

How to place a maximum bound on a number

<?php
  $value = 15;
  $max_value = 10;
  $value = min($max_value, $value);   // 10
?>

Back