Skip to content

Instantly share code, notes, and snippets.

@songfei1983
Last active August 29, 2015 14:12
Show Gist options
  • Save songfei1983/09853229755fd3521e7d to your computer and use it in GitHub Desktop.
Save songfei1983/09853229755fd3521e7d to your computer and use it in GitHub Desktop.
欧几里得度量(euclidean metric)二维
<?php
// 欧几里得度量_百度百科 http://baike.baidu.com/link?url=zAEZl46AoeKqIg0v1n_nPWP5JycEYvoOepRf_lTin_i-nb9YTNQGOFILLYYqTxF3Nho0Wn5vWgNWTYHklq0mE_
function distance()
{
$argv = func_get_args();
$argc = func_num_args();
if ($argc !== sizeof($argv)) return;
$res = $j = intval(NULL);
for (; $j < sizeof($argv[0]); $j++)
{
$res += pow($argv[0][$j] - $argv[1][$j], 2);
}
return sqrt($res);
}
var_dump(distance(array(1, 1), array(4, 5)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment