Skip to content

Instantly share code, notes, and snippets.

@wudi
Forked from songfei1983/EuclidDistance.php
Last active August 29, 2015 14:12
Show Gist options
  • Save wudi/cdaf34d56612d0a429b0 to your computer and use it in GitHub Desktop.
Save wudi/cdaf34d56612d0a429b0 to your computer and use it in GitHub Desktop.
<?php
function distance($data1, $data2) {
$num = 0;
for ($i = 0; $i < sizeof($data1); $i++) {
$num += pow($data1[$i] - $data2[$i], 2);
}
return sqrt($num);
}
var_dump(distance(array(1, 1), array(4, 5)));//int(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment