Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.32 KB | None | 0 0
  1. <?php
  2.  
  3. $coordinates = [
  4.     [0, 2],
  5.     [2, 4],
  6.     [4, 6]
  7. ];
  8.  
  9. $count = count($coordinates);
  10. $x = $y = 0;
  11.  
  12. foreach( $coordinates as $coordinate ) {
  13.     $x += $coordinate[0];
  14.     $y += $coordinate[1];
  15. }
  16.  
  17. $avgX = ceil( $x / $count );
  18. $avgY = ceil( $y / $count );
  19.  
  20. echo "Average distance is: X: " . $avgX . ", Y: " . $avgY;
  21.  
  22. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement