Foreach in middle of return statement
<p>I'm working on a tagging system for an image site, and I have:</p>

<pre><code>function formatImage($url, $description, $tags){

if(empty($description)){

    $description = "&lt;i&gt;No description avaliable.&lt;/i&gt;";

}

$tags = array("One", "Two");
$added = "May 23, 2011";

return '
    &lt;div id="single" class="image"&gt;
        &lt;div id="image"&gt;
            &lt;img src="'.$url.'" /&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id="meta"&gt;

        &lt;dl&gt;
            &lt;dt&gt;Description&lt;/dt&gt;

            &lt;dd&gt;'.$description.'&lt;/dd&gt;
            &lt;dt&gt;Added on&lt;/dt&gt;
            &lt;dd&gt;'.$added.'&lt;/dd&gt;
            &lt;dt&gt;Tagged&lt;/dt&gt;
            &lt;dd id="tags"&gt;'.
                foreach($tags as $tag){
                    return '&lt;a href="/tagged/'.$tag.'"&gt;'.$tag.'&lt;/a&gt;;
                }
                .'
            &lt;/dd&gt;
        &lt;/dl&gt;

    &lt;/div&gt;';
</code></pre>

<p>And then farther down in functions.php:</p>

<pre><code>function pullImage($id){

    dbCon();

    $sql = "SELECT * FROM images WHERE id='$id'";
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);

    $url = $row['url'];
    $description = $row['description'];

    //Tags
    $sql = "SELECT * FROM tags WHERE itemid='$id'";
    $result = mysql_query($sql);

    $tags = array();        

    while($row = mysql_fetch_assoc($result)){

        array_push($tags, $row['tag']);

    }

    //$tags = $tags;

    $image = formatImage($url, $description, $tags);

    echo $image;

}
</code></pre>

<p>And the problem I have is the <code>foreach</code> inside the <code>return</code> statement of the format function. I'm really confused as to how to make this work. How does one go about a function inside a return?</p>
