Home > Backend Development > PHP Tutorial > php循环,该怎么解决

php循环,该怎么解决

WBOY
Release: 2016-06-13 11:48:49
Original
963 people have browsed it

php循环



    • php循环,该怎么解决

    • php循环,该怎么解决

    • php循环,该怎么解决






    • php循环,该怎么解决

    • php循环,该怎么解决

    • php循环,该怎么解决






    • php循环,该怎么解决

    • php循环,该怎么解决

    • php循环,该怎么解决




  • 上边的形式该怎么循环,新手求救。。。。
    ------解决方案--------------------
    $arr = array(<br />    'images/small_case_1.jpg',<br />    'images/small_case_2.jpg',<br />    'images/small_case_3.jpg',<br />    'images/small_case_4.jpg',<br />    'images/small_case_5.jpg',<br />    'images/small_case_6.jpg',<br />    'images/small_case_7.jpg',<br />    'images/small_case_8.jpg',<br />    'images/small_case_9.jpg'<br />);<br /><br />function arr2li($arr){<br />    $html  = '';<br />    if(is_array($arr) && !empty($arr)){<br />        $count = count($arr);<br />        for($i=0; $i<$count; $i++){<br />            $rem = $i%3;<br />            $html .= ($i!=0 && $rem==0) ? "</ul>\n\r</li>\n\r" : "";<br />            $html .= ($rem==0) ? "<li>\n\r<ul>\n\r" : "";<br />            $html .= sprintf("<li><img  src=\"%s\"/ alt="php循环,该怎么解决" ></li>\n\r", $arr[$i]);<br />            $html .= ($i+1==$count) ? "</ul>\n\r</li>" : "";<br />        }<br />    }<br />    return $html;<br />}<br /><br />/*<br /><br /><li><br /><br /><ul><br /><br /><li><img  src="images/small_case_1.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /><li><img  src="images/small_case_2.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /><li><img  src="images/small_case_3.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /></ul><br /><br /></li><br /><br /><li><br /><br /><ul><br /><br /><li><img  src="images/small_case_4.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /><li><img  src="images/small_case_5.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /><li><img  src="images/small_case_6.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /></ul><br /><br /></li><br /><br /><li><br /><br /><ul><br /><br /><li><img  src="images/small_case_7.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /><li><img  src="images/small_case_8.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /><li><img  src="images/small_case_9.jpg"/ alt="php循环,该怎么解决" ></li><br /><br /></ul><br /><br /></li><br />*/<br /><br />echo arr2li($arr);
    Copy after login

    ------解决方案--------------------
    $result=mysql_query("select * from case_list"); <br />while($row=mysql_fetch_assoc($result)){<br />       $ar[]=$row;<br />}<br />foreach(array_chunk($ar,3) as $v){<br />    echo "<li>\n<ul>\n";<br />	foreach($v as $vl) echo "<li><img src='{$vl['cl_pic']}' alt=''/></li>\n";<br />	echo "</ul>\n</li>\n";<br />}
    Copy after login
    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