note 118982 added to function.explode

From: Date: Fri, 11 Mar 2016 13:54:52 +0000
Subject: note 118982 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-205140@lists.php.net to get a copy of this message
// .-------\/. // ''-------. |' | //| '| \/\/\/| | //| \/\/\/ | | //| /\/\/\ /\/\/\| | //| _.' '.__ | //| |\ \ / /| | //| | \ \ / / | | //|_ | \ _\ /_/ |_| <?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'); ---- Server IP: 72.52.91.14 Probable Submitter: 200.242.41.158 ---- Manual Page -- http://php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/118982 Del: integrated -- https://master.php.net/note/delete/118982/integrated Del: useless -- https://master.php.net/note/delete/118982/useless Del: bad code -- https://master.php.net/note/delete/118982/bad+code Del: spam -- https://master.php.net/note/delete/118982/spam Del: non-english -- https://master.php.net/note/delete/118982/non-english Del: in docs -- https://master.php.net/note/delete/118982/in+docs Del: other reasons-- https://master.php.net/note/delete/118982 Reject -- https://master.php.net/note/reject/118982 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205140) next »