Php foreach loop wrapping every 2 items

后端 未结 6 1473
梦谈多话
梦谈多话 2021-02-06 08:03
query(a
6条回答
  •  悲&欢浪女
    2021-02-06 08:40

    Or this:

    ";
            echo "$child";
        }
        if($i==2){
            echo "$child";
            echo ""
            $i=0;
        }
    }
    

    [UPDATE]

    This bugs me: An odd count of children could possibly lead to a row without closing tag. While most Browser will just add the tag on render and you will have no problems at all, this is still not 100% correct.

    On odd children count, you would want a check and a closing row after the foreach loop like this:

    if($i==1){
        echo "";
    }
    

    If $i == 1 after the loop, it was an odd count of children, and the row have to be closed.

    [/UPDATE]

提交回复
热议问题