Home > Article > Backend Development > How efficient is PHP in introducing functions in foreach?
For example, I run a foreach loop:
<code>foreach(func() as $row){ echo $row; } </code>
At this time, does func() run once or multiple times?
Do you need to use it? As mentioned on the Internet, in order to optimize efficiency, define it first:
<code>$arr=func();</code>
Execute again:
<code>foreach($arr as $row){ echo $row; }</code>