Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
/* Дан массив с числами. Найдите сумму элементов,
расположенных от начала массива до первого отрицательного числа.
*/
$arr = [1, 2, 3, 6, -1, 4, 5];
$sum = 0;
$pos = 0;
array_walk($arr, function ($a, $b) use($pos) {
if ($a < 0) {
$pos = $b;
}
});
var_dump($pos);die();
// $sum = array_sum($posArr);