Answer the question
In order to leave comments, you need to log in
The simplest addition?
Hello. I've run into this problem for the millionth time and can't think of anything.
I want to put it like this:
<font color="black"><a href="http://s-c.me/23046/s">Copy Source</a> | <a href="http://s-c.me/23046/h">Copy HTML</a><ol> <li><font color="#696969">//Высчитываем суммы</font></li> <li><font color="#cc6633">$types_sum</font> = <font color="#0000ff">array</font>();</li> <li> </li> <li><font color="#0000ff">foreach</font>(<font color="#cc6633">$types</font>[$type] <font color="#0000ff">as</font> <font color="#cc6633">$project</font>)</li> <li>{</li> <li> <font color="#0000ff">foreach</font>(<font color="#cc6633">$project</font> <font color="#0000ff">as</font> <font color="#cc6633">$source</font> => <font color="#cc6633">$stages</font>)</li> <li> {</li> <li> <font color="#0000ff">foreach</font>(<font color="#cc6633">$stages</font> <font color="#0000ff">as</font> <font color="#cc6633">$stage</font> => <font color="#cc6633">$time</font>)</li> <li> {</li> <li> <font color="#cc6633">$types_sum</font>[<font color="#cc6633">$source</font>][<font color="#cc6633">$stage</font>] += <font color="#cc6633">$time</font>;</li> <li> }</li> <li> }</li> <li>} </li> </ol></font>
<font color="black"><a href="http://s-c.me/23047/s">Copy Source</a> | <a href="http://s-c.me/23047/h">Copy HTML</a><ol> <li><font color="#696969">//Высчитываем суммы</font></li> <li><font color="#cc6633">$types_sum</font> = <font color="#0000ff">array</font>();</li> <li> </li> <li><font color="#0000ff">foreach</font>(<font color="#cc6633">$types</font>[$type] <font color="#0000ff">as</font> <font color="#cc6633">$project</font>)</li> <li>{</li> <li> <font color="#0000ff">foreach</font>(<font color="#cc6633">$project</font> <font color="#0000ff">as</font> <font color="#cc6633">$source</font> => <font color="#cc6633">$stages</font>)</li> <li> {</li> <li> <font color="#0000ff">foreach</font>(<font color="#cc6633">$stages</font> <font color="#0000ff">as</font> <font color="#cc6633">$stage</font> => <font color="#cc6633">$time</font>)</li> <li> {</li> <li> <font color="#0000ff">if</font>(<font color="#0000ff">isset</font>(<font color="#cc6633">$types_sum</font>[<font color="#cc6633">$source</font>][<font color="#cc6633">$stage</font>]))</li> <li> {</li> <li> <font color="#cc6633">$types_sum</font>[<font color="#cc6633">$source</font>][<font color="#cc6633">$stage</font>] += <font color="#cc6633">$time</font>;</li> <li> }</li> <li> <font color="#0000ff">else</font></li> <li> {</li> <li> <font color="#cc6633">$types_sum</font>[<font color="#cc6633">$source</font>][<font color="#cc6633">$stage</font>] = <font color="#cc6633">$time</font>;</li> <li> }</li> <li> }</li> <li> }</li> <li>} </li> </ol></font>
Answer the question
In order to leave comments, you need to log in
Try changing the error warning level: en2.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
I think this is the maximum =)
if( !isset($types_sum[$source][$stage]) )
$types_sum[$source][$stage] = 0;
$types_sum[$source][$stage] += $time;
initializing a variable (or array element) before use is not a problem. so let it be as it is.
(although you can smartly suggest changing the architecture).
As an option:
<?php
//Высчитываем суммы
$types_sum = array();
foreach($types[$type] as $project)
{
foreach($project as $source => $stages)
{
$stages_sum = array_fill_keys(array_keys($stages), 0);
foreach($stages as $stage => $time)
{
$stages_sum[$stage] += $time;
}
$types_sum[$source] = $stages_sum;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question