php練習:每5個商品一排

來源:互聯網
上載者:User

標籤:

 

老闆說:

我要一行5個商品,每個長得都不一樣

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>練習</title><style>    li{list-style: none;}    .slide-content li{float:left;width:100px;height:100px;border:1px solid #000;margin:5px;line-height: 100px;color:#000;text-align: center;}    .li-1{background:red;}    .li-2{background:yellow;}    .li-3{background:blue;}    .li-4{background:green;}    .li-5{background:gray;}</style></head><body><?php//商品組至少5個噢$items=array(    array("name"=>"product1","price"=>10),    array("name"=>"product2","price"=>20),    array("name"=>"product3","price"=>30),    array("name"=>"product4","price"=>40),    array("name"=>"product5","price"=>10));//一行顯示5個    $li_n=5;    //寶貝數    $p_num=count($items)+1;        //迴圈的ul數,cei(1.5)=2    $ul_n=ceil($p_num/$li_n);    for($i=1;$i<$ul_n;$i++){        $li_nav=1;        echo ‘<ul class="slide-content">‘;            foreach($items as $key => $item){                /*listart*/                $s_n=$key+1;                $end_q=$i*$li_n;                $star_q=$end_q-$li_n;                /*1-5,5-10,10-15等,li_nav每次從1開始*/                if($s_n>$star_q and $s_n<=$end_q){                    echo ‘<li class="li-‘.$li_nav.‘">‘.$item[‘name‘].‘</li>‘;                    $li_nav++;                }                    /*liend*/            }    echo ‘</ul>‘;    }?></body></html>

 

php練習:每5個商品一排

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.