note 118982 deleted from function.explode by tularis

From: Date: Sat, 12 Mar 2016 20:42:29 +0000
Subject: note 118982 deleted from function.explode by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205144@lists.php.net to get a copy of this message
Note Submitter: r3x dot r0dr1gu35 at gmail dot com ---- // .-------\/. // ''-------. |' | //| '| \/\/\/| | //| \/\/\/ | | //| /\/\/\ /\/\/\| | //| _.' '.__ | //| |\ \ / /| | //| | \ \ / / | | //|_ | \ _\ /_/ |_| <?php // Function for sum intervals of an array function array_sum_interval($array_external, $interval){ $n_interval=explode(":", $interval); $sum = 0; for($i=$n_interval[0]; $i < ($n_interval[1]+1) ; $i++){ $sum += $array_external[$i]; } return $sum; } // Function for sum a interval of an array function array_sum_intervals($array_external, $intervals){ $n_intervals=explode(";", $intervals); $array_amount = count($n_intervals); $result = 0; for($i=0; $i < $array_amount ; $i++){ $result += array_sum_interval($array_external, $n_intervals[$i]); } return $result; } $test = array(1,2,4,8,16,32,128); echo 'simple interval - '.array_sum_interval($test, '1:3'); echo '<br>'; echo 'composed interval - '.array_sum_intervals($test, '2:3;5:6');

« previous php.notes (#205144) next »