I have an array like this $arr = array(2, -3, 6, 1);
And I only want to select the positive numbers to be able to sum the others between them.
So I wrote this code, but I'm a bit lost on how to select the elements I only want to do something with them, like summing them.
$sum = implode(",", $arr);
for($i = 0; $i <= strlen($sum); $i++) {
if($i <= 0) {
} else {
return explode(",", array_sum($i));
}
}
}
array_filter, no need to use an explicit loop: php.net/manual/en/function.array-filter.php