Insert “element” among other “elements” of the array (loop) php

后端 未结 3 993
遥遥无期
遥遥无期 2021-01-29 11:35

my code causes the images to appear randomly within the page. But how to insert an \"element\" (in my case would be a div) between these images?



        
3条回答
  •  不知归路
    2021-01-29 12:24

    Go with the most readable solution - the one that doesn't make you fall and debug later when changing something.

    $splitAtNumber = 2; // or dynamically use count($myImagesList) / 2 or ....
    
    // output first part of the array
    for ($i = 0; $i < $splitAtNumber; $i++) {
        echo '';
    }
    
    // Output your content
    echo 'content';
    
    // Output second part of the array
    for ($i = splitAtNumber; $i < count($myImagesList); $i++) {
        echo '';
    }
    

提交回复
热议问题