Cleaner way of using modulus for columns

后端 未结 4 1903
一个人的身影
一个人的身影 2021-01-26 10:31

I currently have a list (

    ) of people that I have divided up into two columns. But after finishing the code for it I keept wondering if there is a more effective or cle
4条回答
  •  不思量自难忘°
    2021-01-26 11:08

    Dont know whether this is what @llia meant, but what about have the for loops like this:

    //declare how many columns are needed
    $cols=2;
    
    //iterate over each row of entries (down the column)
    for ($i=0;i<$count;i+=cols){ 
    
         echo "
      "; //entry loop (across the row) for($j=0;j<$cols;j++){ //whose line is it anyway? $uid = $areaArray[$i+$j]; echo "
    • {$users[$uid]->profile_lastname}
    • "; } //end entry loop echo "
    "; } //end row loop

    that way, you can set however many columns you like.

    Forgive me if I missed something as I'm waiting for the kettle to boil to get my much needed caffine!

提交回复
热议问题