Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function replace($arr) {
- if((count($arr)%2)==0) {
- $res=[];
- for($i=0; $i<count($arr); $i++) {
- if($i==(count($arr)/2-1)) $res[] = $arr[$i]+$arr[$i+1];
- else if($i!=(count($arr)/2)) $res[] = $arr[$i];
- return $res;
- }
- }else return $arr;
- }
- print_r(replace([7, 2, 2, 5, 10, 7]));
- echo "<br>";
- print_r(replace([-5,-5,10]));
- echo "<br>";
- print_r(replace([45, 23, 12, 33, 12, 453, -234, -45]));
- echo "<br>";
- print_r(replace([2,8]));
- echo "<br>";
- print_r(replace([-12, 34, 40, -5, -12, 4, 0, 0, -12]));
- echo "<br>";
- print_r(replace([9, 0, 15, 9]));
- echo "<br>";
- print_r(replace([-6, 6, -6]));
- echo "<br>";
- print_r(replace([26, 26, -17]));
- echo "<br>";
- print_r(replace([-7, 5, 5, 10]));
- echo "<br>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement