I need to update a value in an array inside a loop. Normally this works fine, but something about this loop is causing the memory to max out.
while ($watering_window['total_run_time'] > $water_window_total)
{
foreach ($master_schedule as &$_ms)
{
$current_soak_time = $_ms['between_starts'] - $_ms['total_run_time'];
if ($current_soak_time > 0)
{
$new_soak_time = ceil($current_soak_time * 0.9);
$_ms['between_starts'] = $_ms['total_run_time'] + $new_soak_time;
$watering_window['total_run_time'] -= $current_soak_time - $new_soak_time;
}
}
}
Something about writing to $_ms['between_starts'] (an existing key) is causing the memory problem. If I change it to write a NEW key (like $_ms['between_starts_new'], no memory problem. I also tried writing a constant value to it (instead of something mathy) and it still timed out.
&$_msvalue? It could be what's causing$_ms['between_starts']to balloon in size (continuous increment), and in turn, cause$current_soak_timeto also balloon, thus not allowing$watering_window['total_run_time'] > $water_window_totalto ever return false. Or do you require$_msto be referenced for other reasons?$watering_window['total_run_time']is supposed to be getting smaller, but it can't because$_ms['between_starts']keeps getting bigger and bigger. And in turn, because of that, as does$current_soak_time. That's how I see it, anyway. You'll have to rewrite your logic and determine whether the reference is actually necessary in this case, because it's directly affecting the outcome of your loop(s).