当前位置:Gxlcms > PHP教程 > php循环解决办法

php循环解决办法

时间:2021-07-01 10:21:17 帮助过:10人阅读

php循环
























  • 上边的形式该怎么循环,新手求救。。。。

    分享到: 更多


    ------解决方案--------------------
    $arr = array(
    'https://www.gxlcms.com/images/small_case_1.jpg',
    'https://www.gxlcms.com/images/small_case_2.jpg',
    'https://www.gxlcms.com/images/small_case_3.jpg',
    'https://www.gxlcms.com/images/small_case_4.jpg',
    'https://www.gxlcms.com/images/small_case_5.jpg',
    'https://www.gxlcms.com/images/small_case_6.jpg',
    'https://www.gxlcms.com/images/small_case_7.jpg',
    'https://www.gxlcms.com/images/small_case_8.jpg',
    'https://www.gxlcms.com/images/small_case_9.jpg'
    );

    function arr2li($arr){
    $html = '';
    if(is_array($arr) && !empty($arr)){
    $count = count($arr);
    for($i=0; $i<$count; $i++){
    $rem = $i%3;
    $html .= ($i!=0 && $rem==0) ? "\n\r\n\r" : "";
    $html .= ($rem==0) ? "
  • \n\r
      \n\r" : "";
      $html .= sprintf("
    • \n\r", $arr[$i]);
      $html .= ($i+1==$count) ? "
    \n\r
  • " : "";
    }
    }
    return $html;
    }

    /*










































  • */

    echo arr2li($arr);

    ------解决方案--------------------
    $result=mysql_query("select * from case_list"); 
    while($row=mysql_fetch_assoc($result)){
    $ar[]=$row;
    }
    foreach(array_chunk($ar,3) as $v){
    echo "
  • \n
      \n";
      foreach($v as $vl) echo "
    • \n";
      echo "
    \n
  • \n";
    }

    人气教程排行