Last active
August 29, 2015 14:12
-
-
Save songfei1983/09853229755fd3521e7d to your computer and use it in GitHub Desktop.
欧几里得度量(euclidean metric)二维
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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