Home > Backend Development > PHP Tutorial > 怎么简化下面代码

怎么简化下面代码

WBOY
Release: 2016-06-23 14:38:20
Original
857 people have browsed it

if($_MODULE[huoqubaobei]!="4"){	$i=-1;	$j=0;    foreach($items as $item){		$i++;        $itemUrl = $uriManager->detailURI($item);         $itemPicUrl = $item->getPicUrl(310);        $itemTitle = $item->title;        $itemPrice = $item->price;        $itemsoldCount = $item->soldCount; echo'<div class="picall picall'.$i.'"><a href="'.$itemUrl.'" class="pic"><img    style="max-width:90%" src="'.$itemPicUrl.'" / alt="怎么简化下面代码" ></a><div class="title"><a href="'.$itemUrl.'" class="wz">'.$itemTitle.'</a><a class="fuhao">¥</a><a class="price">'.$itemPrice.'</a></div></div>';	}}else if($_MODULE[huoqubaobei]=="4"){		$num = count($srtpdz);	    for($i=0;$i<$num;$i++)	    {			echo'<div class="picall picall'.$i.'"><a href="'.$srtpljdz[$i].'" class="pic"><img    style="max-width:90%".$_MODULE["tpgd"].'px;" src="'.$srtpdz[$i].'" / alt="怎么简化下面代码" ></a><div class="title"><a href="'.$srtpljdz[$i].'" class="wz">'.$srbbbt[$i].'</a><a class="fuhao">¥</a><a class="price">'.$srbbjg[$i].'</a></div></div>';		}	}
Copy after login


这个地方div+css写重复了 我想不重复怎么写。。我想了几个小时也想不出好的方法 主要这个循环蛋疼。。


回复讨论(解决方案)

估计不能再压榨多少了

正因为混编代码太繁杂,所以才出现了模板引擎

怎么简化下面代码


';

我想这个不要重复哈

没人知道么???????????????????????

真想把那段echo出来的代码 用另一个函数来输出。

再怎么简化也节省不了多少代码,就这么的吧。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template