Home  >  Article  >  Backend Development  >  How efficient is PHP in introducing functions in foreach?

How efficient is PHP in introducing functions in foreach?

WBOY
WBOYOriginal
2016-10-17 09:12:16872browse

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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn