我工作的一個網站形象標籤系統上,我有:的foreach在return語句中
function formatImage($url, $description, $tags){
if(empty($description)){
$description = "<i>No description avaliable.</i>";
}
$tags = array("One", "Two");
$added = "May 23, 2011";
return '
<div id="single" class="image">
<div id="image">
<img src="'.$url.'" />
</div>
</div>
<div id="meta">
<dl>
<dt>Description</dt>
<dd>'.$description.'</dd>
<dt>Added on</dt>
<dd>'.$added.'</dd>
<dt>Tagged</dt>
<dd id="tags">'.
foreach($tags as $tag){
return '<a href="/tagged/'.$tag.'">'.$tag.'</a>;
}
.'
</dd>
</dl>
</div>';
然後在functions.php中越往下:
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;
}
而且我遇到的問題是format函數的return
語句中的foreach
。我對如何完成這項工作感到非常困惑。一個人如何去回報一個函數?
我只是沒有。 – cweiske