Cleaner way of using modulus for columns

后端 未结 4 1905
一个人的身影
一个人的身影 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:16

    This should do what you want. I pretty much just combined the other two answers so +1 for everyone.

    $cols=3;
    $user_count = count($users);
    
    echo "";
    
    // Column loop
    for($i=0;$i<$cols;$i++){
        echo "";
    }
    echo "
      "; // user loop for($j=$i;$j<$user_count;$j+=$cols){ echo "
    • {$users[$j]->profile_lastname}
    • "; } echo "
    ";

提交回复
热议问题