php function for gathering includes...is there a better way than this?
Don't make your directory structure so vague. Coming into this with no knowledge of your system how am I supposed to know what the "i" directory is? Just call it includes. Also, it is usually a good idea to separate your files based on their types so that they are easier to find. There are many common project directory structures out there. For instance I'm using something similar to Zend's. It looks similar to this.

/root
    /application
        /configs
        /models
        /views
        /controllers
    /data
        /cache
        /logs
    /public
        /js
        /css
        /images


I hope those file names don't indicate that you are actually using globals... There are much better ways to get "global" scope variables without ever using global. Sessions for instance. Globals, in my opinion, should eventually be deprecated. They are an old feature that has been proven faulty and replaced.

array_push() is another old function. Though there is nothing wrong with it, the preferred way to do it now is like so.

$includes[] = $file;


What you are trying to do is usually done with templates rather than PHP. For instance, you'd have a single HTML file with these includes in it already then dynamically change the contents with PHP. For those files that use the $topic variable, you would just perform a check to make sure it exists before including it via PHP. So a very basic template might look like this.

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script type="text/javascript" src="i/globals.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" type="text/css" href="i/globals.css" /&gt;

&lt;!-- SPECIFIC INCLUDES --&gt;

&lt;?php if( is_file( "i/$topic.js" ) : ?&gt;
&lt;script type="text/javascript" src="i/&lt;?php echo $topic.js; ?&gt;"&gt;&lt;/script&gt;
&lt;?php endif; ?&gt;

&lt;?php if( is_file( "i/$topic.css" ) : ?&gt;
&lt;link rel="stylesheet" type="text/css" href="i/&lt;?php echo $topic.css; ?&gt;" /&gt;
&lt;?php endif; ?&gt;

&lt;!-- SPECIFIC INCLUDES --&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;?php if( is_file( "i/$topic.php" ) ) { include "i/$topic.php"; } ?&gt;
&lt;/body&gt;
&lt;/html&gt;