Robots files generation - simplifying foreach code I'm trying to figure out if there's a way I can simplify this code which is used to generate a robots.txt file with numerous rules.  Different files/folders are separated in separate arrays because they're applied differently but in some cases they are applied the same.  In these cases, rather than write out a separate foreach for each one, this is what I'm trying to simplify:

&lt;?php

public function generateRobotsFile($rbfile, $smfile) {
    $tab = array();
    $tab['SemBot'] = array('Googlebot',"bingbot\nCrawl-delay: 5",'MSNBot');

    $tab['Lang'] = array('eb');
    $tab['Files'] = array('address.php','cart.php');
    $tab['Folder'] = array('classes','docs','themes');

    fwrite($writeFd, "\nUser-agent: *\n");
    foreach ($tab['Lang'] as $Lang) {
        fwrite($writeFd, 'Disallow: ' . __PS_BASE_URI__ . $Lang . "\n");
    }
    foreach ($tab['Folder'] as $Folder) {
        fwrite($writeFd, 'Disallow: ' . __PS_BASE_URI__ . $Folder . "\n");
    }

    foreach ($tab['SemBot'] as $SemBot) {
        fwrite($writeFd, "User-agent: ' . $SemBot . "\n");
        foreach ($tab['Files'] as $Files) {
            fwrite($writeFd, 'Disallow: ' . __PS_BASE_URI__ . $Files . "\n");
        }
        foreach ($tab['Folder'] as $Folder) {
            fwrite($writeFd, 'Disallow: ' . __PS_BASE_)URI__ . $Folder . "/\n");
        }
    }


The arrays must remain separated but in some cases they are looped through the same disallow rule so I'm reaching for a foreach array in array but haven't quite grasped it yet.
If number of lines is your primary concern, then really all we can do with this is merge your array creation lines, and use array_merge() to create temporary arrays which you can loop around, like so:

public function generateRobotsFile($rbfile, $smfile)
{
    $tab = array('SemBot' =&gt; array('Googlebot', "bingbot\nCrawl-delay: 5", 'MSNBot'),
                 'Lang'   =&gt; array('eb'),
                 'Files'  =&gt; array('address.php', 'cart.php'),
                 'Folder' =&gt; array('classes', 'docs', 'themes'));
    fwrite($writeFd, "\nUser-agent: *\n");
    foreach(array_merge($tab['Lang'], $tab['Folder']) as $disallow)
    {
        fwrite($writeFd, 'Disallow: ' . __PS_BASE_URI__ . $disallow . "\n");
    }
    foreach($tab['SemBot'] as $SemBot)
    {
        fwrite($writeFd, "User-agent: " . $SemBot . "\n");
        foreach(array_merge($tab['Files'], $tab['Folder']) as $disallow)
        {
            fwrite($writeFd, 'Disallow: ' . __PS_BASE_URI__ . $disallow . "\n");
        }
    }
}