Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP include file in foreach Loop

Tags:

php

Will I be ok doing this?

foreach ($item as $val)
{
    include('external_script.php');
} 

Where external script is about 800 lines of code I want to keep separate for organizational sakes.

Gracious!

like image 814
atwellpub Avatar asked Aug 06 '10 15:08

atwellpub


1 Answers

I guess you should better use a function for this.

Including a file requires to read, parse, and interpret the file. But if you have a function that you just feed with the current $item, it its code is just read, parsed and interpreted once and you won’t have that overhead you would have with including.

like image 154
Gumbo Avatar answered Oct 18 '22 11:10

Gumbo