note 71373 added to function.array-sum

From: Date: Fri, 24 Nov 2006 23:28:25 +0000
Subject: note 71373 added to function.array-sum
Groups: php.notes 
Request: Send a blank email to php-notes+get-120063@lists.php.net to get a copy of this message
I'm not sure if something similar already exists, but I needed it so I made it: <?php /* Performs a pitagoric sum of the elements in $arr The pitagoric sum of a set of values is the square root of the sum of the sqare power of each value. So, for a, b, c it's sqrt(a^2 + b^2 + c^2) */ /* If any element of $arr is an array itself, the array_sum will be used. Alternatively, the values could be used by recursion. Returns the integer part (floor) */ function array_pitag_sum($arr) { if(is_array($arr) { $ret = 0; foreach($arr as $i) { if(is_array($i)) { $s = array_sum($i); $ret += $s*$s; } else { $ret += $i*$i; } } return floor(sqrt($ret)); } else { return $arr; } } ?> ---- Server IP: 193.95.141.37 Probable Submitter: 85.134.141.181 ---- Manual Page -- http://www.php.net/manual/en/function.array-sum.php Edit -- https://master.php.net/note/edit/71373 Del: integrated -- https://master.php.net/note/delete/71373/integrated Del: useless -- https://master.php.net/note/delete/71373/useless Del: bad code -- https://master.php.net/note/delete/71373/bad+code Del: spam -- https://master.php.net/note/delete/71373/spam Del: non-english -- https://master.php.net/note/delete/71373/non-english Del: in docs -- https://master.php.net/note/delete/71373/in+docs Del: other reasons-- https://master.php.net/note/delete/71373 Reject -- https://master.php.net/note/reject/71373 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120063) next »