note 71373 deleted from function.array-sum by salathe

From: Date: Mon, 21 Sep 2020 14:51:10 +0000
Subject: note 71373 deleted from function.array-sum by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215352@lists.php.net to get a copy of this message
Note Submitter: herenvardo at gmail dot com ---- 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; } } ?>

« previous php.notes (#215352) next »