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

How efficient is PHP in introducing functions in foreach?

WBOY
Release: 2016-10-17 09:12:16
Original
897 people have browsed it

For example, I run a foreach loop:

<code>foreach(func() as $row){
echo $row;
}
</code>
Copy after login

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>
Copy after login

Execute again:

<code>foreach($arr as $row){
    echo $row;
}</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template